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