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