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
   */
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
      {
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
        {
166
          // deliver change to product baseline
167
          mLogger.warn("run deliverChange");
916 mhunt 168
          mLogger.fatal("run calling setViewUp");
814 mhunt 169
          setViewUp(buildFileContent.value, false);
866 mhunt 170
 
868 mhunt 171
          if ( mGbeGatherMetricsOnly != null )
172
          {
173
            // special for metrics
174
            // deliverChange on a benign target to get mReportingPackageName and mReportingPackageVersion set up
175
            // nb in the metrics gathering world the <rtagid>build.xml is provided by the master thread
916 mhunt 176
            mLogger.fatal("run calling deliverChange on fullstart");
868 mhunt 177
            deliverChange(null, "fullstart", false);
178
 
179
            String archive = Package.mGbeDpkg;
180
 
181
            if (archive != null)
182
            {
183
              String fs = System.getProperty( "file.separator" );
184
              String destination = archive + fs + mReportingPackageName + fs + mReportingPackageVersion;
185
 
186
              // do this for all unix based platforms
187
              new File( destination ).mkdirs();
188
              new File( destination, "built.sparc" ).createNewFile();
189
              new File( destination, "built.solaris10_sparc32" ).createNewFile();
190
              new File( destination, "built.solaris10_x86" ).createNewFile();
191
              new File( destination, "built.linux_i386" ).createNewFile();
192
            }
193
 
194
          }
195
          else
196
          {
916 mhunt 197
            mLogger.fatal("run calling deliverChange - the actual build");
868 mhunt 198
            deliverChange(null, null, false);
916 mhunt 199
            mLogger.fatal("run calling deliverChange on AbtTearDown");
868 mhunt 200
            deliverChange(null, "AbtTearDown", false);
201
          }
202
 
866 mhunt 203
          if ( mReportingBuildFailureLogFile != null )
204
          {
205
            // tweak the build failure log file in the database
206
            Integer rtagId = mRtagId;
207
 
908 mhunt 208
            // force exclusion by default
209
            int testBuildInstruction = 0;
210
            try
211
            {
212
              testBuildInstruction = Integer.parseInt( mReportingTestBuild );
213
            }
214
            catch( NumberFormatException nfe )
215
            {
216
            }
916 mhunt 217
            mLogger.fatal("run calling excludeFromBuild");
908 mhunt 218
            mReleaseManager.excludeFromBuild(mReportingPackageVersionId, mReportingPackageVersion, rtagId.toString(), null, null, mReportingBuildFailureLogFile, false, testBuildInstruction);
866 mhunt 219
          }
220
 
814 mhunt 221
          mLogger.info("run deliverChange returned");
222
          mSleep = false;
223
        }
224
 
225
      }
226
      catch( SQLException e )
227
      {
228
        // oracle connection issues        
229
         mLogger.warn("run oracle connection issues");
886 mhunt 230
         mException = true;
814 mhunt 231
      }
232
      catch( ExitException e )
233
      {
858 mhunt 234
        mLogger.warn("run ExitException");
814 mhunt 235
        exit = true;
236
      }
237
      catch( InterruptedException e )
238
      {
239
        mLogger.warn("run InterruptedException");
240
      }
241
      catch( Exception e )
242
      {
243
        mLogger.error("run indefinitePause");
868 mhunt 244
        String cause = e.getMessage();
245
 
246
        if ( cause != null )
814 mhunt 247
        {
868 mhunt 248
          try
249
          {
250
            // notify first
251
            // many reasons for indefinite pause, including database related, so do database last
896 mhunt 252
            mRecoverable = false;
253
 
254
            if ( cause.compareTo(Package.mRecoverable) == 0 )
255
            {
256
              mRecoverable = true;
257
            }
258
 
868 mhunt 259
            indefinitePause(rippleEngine, cause);
260
            mReleaseManager.indefinitePause();
886 mhunt 261
            // DEVI 51366 force sleep at beginning of while loop
262
            mException = true;
868 mhunt 263
          }
264
          catch( Exception f )
265
          {
266
            mLogger.error("run indefinitePause failed");
267
          }
814 mhunt 268
        }
269
      }
270
    }
271
  }
272
 
273
  /**returns 'S'
274
   */
275
  protected char getMode()
276
  {
277
    mLogger.debug("getMode");
278
    return 'S';
279
  }
280
}