Subversion Repositories DevTools

Rev

Rev 4123 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4123 Rev 4285
Line 1... Line 1...
1
package com.erggroup.buildtool.daemon;
1
package com.erggroup.buildtool.daemon;
2
 
2
 
3
import com.erggroup.buildtool.daemon.BuildThread;
3
import com.erggroup.buildtool.daemon.BuildThread;
4
import com.erggroup.buildtool.ripple.MutableInt;
-
 
5
import com.erggroup.buildtool.ripple.MutableString;
4
import com.erggroup.buildtool.ripple.MutableString;
6
import com.erggroup.buildtool.ripple.Package;
5
import com.erggroup.buildtool.ripple.Package;
7
import com.erggroup.buildtool.ripple.ReleaseManager;
6
import com.erggroup.buildtool.ripple.ReleaseManager;
8
import com.erggroup.buildtool.ripple.RippleEngine;
7
import com.erggroup.buildtool.ripple.RippleEngine;
-
 
8
import com.erggroup.buildtool.ripple.RunLevelData;
9
 
9
 
10
import java.io.File;
10
import java.io.File;
11
import java.sql.SQLException;
11
import java.sql.SQLException;
12
import org.apache.log4j.Logger;
12
import org.apache.log4j.Logger;
13
 
13
 
-
 
14
/**
14
/**Slave Thread sub component
15
 * Slave Thread sub component
15
 */
16
 */
16
public class SlaveThread
17
public class SlaveThread extends BuildThread
17
  extends BuildThread
-
 
18
{
18
{
19
 
19
 
20
  /**Logger
20
	/**
21
   * @attribute
21
	 * Logger
22
   */
22
	 * 
23
  private static final Logger mLogger = Logger.getLogger(SlaveThread.class);
23
	 * @attribute
24
 
24
	 */
25
  /**constructor
25
	private static final Logger mLogger = Logger.getLogger(SlaveThread.class);
26
   */
26
 
27
  public SlaveThread(int rtag_id, int rcon_id, String unitTest)
27
	/**
28
  {
28
	 * constructor
29
    mLogger.warn("SlaveThread rtag_id " + rtag_id + " rcon_id " + rcon_id);
29
	 */
30
    mRtagId = rtag_id;
30
	public SlaveThread(int rtag_id, int rcon_id, String unitTest)
31
    mRconId = rcon_id;
31
	{
32
    if ( unitTest == null )
32
		mLogger.warn("SlaveThread rtag_id " + rtag_id + " rcon_id " + rcon_id);
33
    {
33
		mRtagId = rtag_id;
34
      unitTest = new String();
34
		mRconId = rcon_id;
35
    }
35
		if (unitTest == null)
36
    mUnitTest = unitTest;
36
		{
37
  }
37
			unitTest = new String();
38
 
38
		}
39
  /**implements the sequence diagrams consume build files, allowed to proceed, check environment
39
		mUnitTest = unitTest;
40
   */
40
	}
41
  public void run()
41
 
42
  {
42
	/**
43
    Integer id = new Integer(mRtagId);
43
	 * implements the sequence diagrams consume build files, allowed to proceed,
44
    setName(id.toString());
44
	 * check environment
45
    mLogger.warn("run");
45
	 */
46
    boolean exit = false;
46
	public void run()
47
    RippleEngine rippleEngine = new RippleEngine(mReleaseManager, mRtagId, true);
47
	{
48
    MutableString buildFileContent = new MutableString();
48
		Integer id = new Integer(mRtagId);
49
 
49
		setName(id.toString());
50
    while(!exit)
50
		mLogger.warn("run");
51
    {
51
		boolean exit = false;
52
      try
52
		RippleEngine rippleEngine = new RippleEngine(mReleaseManager, mRtagId, true);
53
      {
53
		MutableString buildFileContent = new MutableString();
54
        mLogger.fatal("run calling sleepCheck");
54
 
55
        sleepCheck();
55
		while (!exit)
56
        mLogger.fatal("run calling rippleEngine.collectMetaData");
56
		{
57
        rippleEngine.collectMetaData();
57
			try
58
        
58
			{
59
        if ( Thread.currentThread().isInterrupted() )
59
				mLogger.fatal("run calling sleepCheck");
60
        {
60
				sleepCheck();
61
          mLogger.warn("run is interrupted");
61
				mLogger.fatal("run calling rippleEngine.collectMetaData");
62
          // unit test technique
62
				rippleEngine.collectMetaData();
63
          throw new ExitException();
63
 
64
        }
64
				if (Thread.currentThread().isInterrupted())
65
        
65
				{
66
        if ( mUnitTest.compareTo("unit test spawn thread") == 0)
66
					mLogger.warn("run is interrupted");
67
        {
67
					// unit test technique
68
          throw new Exception();
68
					throw new ExitException();
69
        }
69
				}
70
        
70
 
71
        // allowed to proceed
71
				if (mUnitTest.compareTo("unit test spawn thread") == 0)
72
        if ( mUnitTest.compareTo("unit test consume build files") != 0)
72
				{
73
        {
73
					throw new Exception();
74
          mRunLevel = RunLevel.IDLE;
74
				}
75
          mLogger.warn("run changing run level to IDLE for rcon_id " + mRconId);
75
 
76
          mLogger.fatal("run calling rmRunLevel.persistNew to set IDLE");
76
				// allowed to proceed
77
          mRunLevel.persistNew(mReleaseManager, mRconId);
77
				if (mUnitTest.compareTo("unit test consume build files") != 0)
78
 
78
				{
79
          mLogger.warn("run checking allowedToProceed");
79
					mRunLevel = RunLevel.IDLE;
80
          mLogger.fatal("run calling allowedToProceed");
80
					mLogger.warn("run changing run level to IDLE for rcon_id " + mRconId);
81
          allowedToProceed(false);
81
					mLogger.fatal("run calling rmRunLevel.persistNew to set IDLE");
82
          mLogger.info("run allowedToProceed returned");
82
					mRunLevel.persistNew(mReleaseManager, mRconId);
83
        }
83
 
84
        
84
					mLogger.warn("run checking allowedToProceed");
85
        mRunLevel = RunLevel.WAITING;
85
					mLogger.fatal("run calling allowedToProceed");
86
        mLogger.warn("run changing run level to WAITING for rcon_id " + mRconId);
86
					allowedToProceed(false);
87
        mLogger.fatal("run calling rmRunLevel.persist to set WAITING");
87
					mLogger.info("run allowedToProceed returned");
88
        mRunLevel.persist(mReleaseManager, mRconId);
88
				}
89
 
89
 
90
        // consume build files
90
				// Indicate that the Slave is WAITING - for a job
91
        mLogger.warn("run consume build files");
91
				mRunLevel = RunLevel.WAITING;
92
        buildFileContent.value = "";
92
				mLogger.warn("run changing run level to WAITING for rcon_id " + mRconId);
93
        boolean logWarning = true;
93
				mLogger.fatal("run calling rmRunLevel.persist to set WAITING");
94
        
94
				mRunLevel.persist(mReleaseManager, mRconId);
95
        // additional handshake
95
 
96
        // Master waits for Slave to be in state waiting
96
				// consume build files
97
        // wait for the Master to signal we are active
97
				mLogger.warn("run consume build files");
98
        MutableInt rconId = new MutableInt();
98
				buildFileContent.value = "";
99
        MutableInt current_run_level = new MutableInt();
99
				boolean logWarning = true;
100
        
100
 
101
        do
101
				// Wait for Salve to be set as Active
102
        {
102
				for (;;)
103
          mLogger.fatal("run calling mReleaseManager.querySingleRunLevel");
103
				{
104
          mReleaseManager.querySingleRunLevel(mRconId);
104
					mLogger.fatal("run calling mReleaseManager.querySingleRunLevel");
105
          mLogger.fatal("run calling mReleaseManager.getFirstRunLevel");
105
					mReleaseManager.querySingleRunLevel(mRconId);
106
          if ( !mReleaseManager.getFirstRunLevel(rconId, current_run_level) )
106
 
107
          {
107
					// Detect this daemon has been un-configured
108
            mLogger.warn("run no longer configured 1");
108
					if (mReleaseManager.mRunLevelCollection.isEmpty())
109
            throw new ExitException();
109
					{
110
          }
110
						mLogger.warn("run no longer configured 1");
111
          
111
						throw new ExitException();
112
          if (current_run_level.value != ReleaseManager.DB_ACTIVE)
112
					}
113
          {
113
 
114
            try
114
					RunLevelData rl = mReleaseManager.mRunLevelCollection.firstElement();
115
            {
115
					if (rl.get_current_run_level() != ReleaseManager.DB_ACTIVE)
116
              if ( logWarning )
116
					{
117
              {
117
						try
118
                mLogger.warn("run sleep 3 secs waiting for Master to set Slave run level ACTIVE");
118
						{
119
                logWarning = false;
119
							if (logWarning)
120
              }
120
							{
121
              else
121
								mLogger.warn("run sleep 3 secs waiting for Master to set Slave run level ACTIVE");
122
              {
122
								logWarning = false;
123
                mLogger.info("run sleep 3 secs waiting for Master to set Slave run level ACTIVE");
123
							} else
124
              }
124
							{
125
              // to do, sleep for periodicMs
125
								mLogger.info("run sleep 3 secs waiting for Master to set Slave run level ACTIVE");
126
              mLogger.fatal("run calling Thread.sleep for 3 secs");
126
							}
127
              Thread.sleep(3000);
127
							// to do, sleep for periodicMs
128
              mLogger.info("run sleep returned");
128
							mLogger.fatal("run calling Thread.sleep for 3 secs");
129
            }
129
							Thread.sleep(3000);
130
            catch (InterruptedException e)
130
							mLogger.info("run sleep returned");
131
            {
131
						} catch (InterruptedException e)
132
              mLogger.warn("run caught InterruptedException");
132
						{
133
            }
133
							mLogger.warn("run caught InterruptedException");
134
          }
134
						}
135
        } while (current_run_level.value != ReleaseManager.DB_ACTIVE);
135
					} else
136
 
136
					{
137
        mLogger.fatal("run calling mReleaseManager.queryRunLevel");
137
						// Have been set to Active
138
        mReleaseManager.queryRunLevel(mRconId, buildFileContent);
138
						break;
139
        
139
					}
140
        if ( buildFileContent.value.compareTo("") == 0)
140
				}
141
        {
141
 
142
          mLogger.warn("run no longer configured 2");
142
				mLogger.fatal("run calling mReleaseManager.queryRunLevel");
143
          throw new ExitException();
143
				mReleaseManager.queryBuildFile(mRconId, buildFileContent);
144
        }
144
 
145
        
145
				if (buildFileContent.value.compareTo("") == 0)
146
        mLogger.info("run consumed build files");
146
				{
147
 
147
					mLogger.warn("run no longer configured 2");
148
        if ( mUnitTest.compareTo("unit test consume build files") == 0 )
148
					throw new ExitException();
149
        {
149
				}
150
          throw new ExitException();
150
 
151
        }
151
				mLogger.info("run consumed build files");
152
 
152
 
153
        // set CURRENT_BUILD_FILES to null
153
				if (mUnitTest.compareTo("unit test consume build files") == 0)
154
        mLogger.fatal("run calling mReleaseManager.clearBuildFile");
154
				{
155
        mReleaseManager.clearBuildFile(mRconId);
155
					throw new ExitException();
156
 
156
				}
157
        // check environment
157
 
158
        mLogger.warn("run checkEnvironment");
158
				// set CURRENT_BUILD_FILES to null
159
        mLogger.fatal("run calling checkEnvironment");
159
				mLogger.fatal("run calling mReleaseManager.clearBuildFile");
160
        checkEnvironment();
160
				mReleaseManager.clearBuildFile(mRconId);
161
        mLogger.info("run checkEnvironment returned");
161
 
162
        
162
				// check environment
163
        mSleep = true;
163
				mLogger.warn("run checkEnvironment");
164
        if ( buildFileContent.value.compareTo(mDummyBuildFileContent) != 0 )
164
				mLogger.fatal("run calling checkEnvironment");
165
        {
165
				checkEnvironment();
166
          // Start of a build cycle. Set new log file to capture entire build log
166
				mLogger.info("run checkEnvironment returned");
167
          flagStartBuildCycle();
167
 
168
 
168
				mSleep = true;
169
          // deliver change to product baseline
169
				if (buildFileContent.value.compareTo(mDummyBuildFileContent) != 0)
170
          mLogger.warn("run deliverChange");
170
				{
171
          mLogger.fatal("run calling setViewUp");
171
					// Start of a build cycle. Set new log file to capture
172
          setViewUp(buildFileContent.value, false);
172
					// entire build log
173
          
173
					flagStartBuildCycle();
174
          if ( mGbeGatherMetricsOnly != null )
174
 
175
          {
175
					// deliver change to product baseline
176
            // special for metrics
176
					mLogger.warn("run deliverChange");
177
            // deliverChange on a benign target to get mReportingPackageName and mReportingPackageVersion set up
177
					mLogger.fatal("run calling setViewUp");
178
            // nb in the metrics gathering world the <rtagid>build.xml is provided by the master thread
178
					setViewUp(buildFileContent.value, false);
179
            mLogger.fatal("run calling deliverChange on fullstart");
179
 
180
            deliverChange(null, "fullstart", false);
180
					if (mGbeGatherMetricsOnly != null)
181
            
181
					{
182
            String archive = Package.mGbeDpkg;
182
						// special for metrics
183
            
183
						// deliverChange on a benign target to get
184
            if (archive != null)
184
						// mReportingPackageName and mReportingPackageVersion
185
            {
185
						// set up
186
              String fs = System.getProperty( "file.separator" );
186
						// nb in the metrics gathering world the
187
              String destination = archive + fs + mReportingPackageName + fs + mReportingPackageVersion;
187
						// <rtagid>build.xml is provided by the master thread
188
              
188
						mLogger.fatal("run calling deliverChange on fullstart");
189
              // do this for all unix based platforms
189
						deliverChange(null, "fullstart", false);
190
              new File( destination ).mkdirs();
190
 
191
              new File( destination, "built.sparc" ).createNewFile();
191
						String archive = Package.mGbeDpkg;
192
              new File( destination, "built.solaris10_sparc32" ).createNewFile();
192
 
193
              new File( destination, "built.solaris10_x86" ).createNewFile();
193
						if (archive != null)
194
              new File( destination, "built.linux_i386" ).createNewFile();
194
						{
195
            }
195
							String fs = System.getProperty("file.separator");
196
            
196
							String destination = archive + fs + mReportingPackageName + fs + mReportingPackageVersion;
197
          }
197
 
198
          else
198
							// do this for all unix based platforms
199
          {
199
							new File(destination).mkdirs();
200
            mLogger.fatal("run calling deliverChange - the actual build");
200
							new File(destination, "built.sparc").createNewFile();
201
            deliverChange(null, null, false);
201
							new File(destination, "built.solaris10_sparc32").createNewFile();
202
            mLogger.fatal("run calling deliverChange on AbtTearDown");
202
							new File(destination, "built.solaris10_x86").createNewFile();
203
            deliverChange(null, "AbtTearDown", false);
203
							new File(destination, "built.linux_i386").createNewFile();
204
          }
204
						}
205
          
205
 
206
          if ( mReportingBuildFailureLogFile != null )
206
					} else
207
          {
207
					{
208
            // tweak the build failure log file in the database
208
						mLogger.fatal("run calling deliverChange - the actual build");
209
            Integer rtagId = mRtagId;
209
						deliverChange(null, null, false);
210
            
210
						mLogger.fatal("run calling deliverChange on AbtTearDown");
211
            // force exclusion by default
211
						deliverChange(null, "AbtTearDown", false);
212
            int testBuildInstruction = 0;
212
					}
213
            try
213
 
214
            {
214
					if (mReportingBuildFailureLogFile != null)
215
              testBuildInstruction = Integer.parseInt( mReportingTestBuild );
215
					{
216
            }
216
						// tweak the build failure log file in the database
217
            catch( NumberFormatException nfe )
217
						Integer rtagId = mRtagId;
218
            {
218
 
219
            }
219
						// force exclusion by default
220
            mLogger.fatal("run calling excludeFromBuild");
220
						int testBuildInstruction = 0;
221
            mReleaseManager.excludeFromBuild(mReportingPackageVersionId, mReportingPackageVersion, rtagId.toString(), null, null, mReportingBuildFailureLogFile, false, testBuildInstruction);
221
						try
222
          }
222
						{
223
          
223
							testBuildInstruction = Integer.parseInt(mReportingTestBuild);
224
          mLogger.info("run deliverChange returned");
224
						} catch (NumberFormatException nfe)
225
          mSleep = false;
225
						{
226
        }
226
						}
227
        
227
						mLogger.fatal("run calling excludeFromBuild");
228
      }
228
						mReleaseManager.excludeFromBuild(mReportingPackageVersionId, mReportingPackageVersion,
229
      catch( SQLException e )
229
								rtagId.toString(), null, null, mReportingBuildFailureLogFile, false,
230
      {
230
								testBuildInstruction);
231
        // oracle connection issues        
231
					}
232
         mLogger.warn("run oracle connection issues");
232
 
233
         mException = true;
233
					mLogger.info("run deliverChange returned");
234
      }
234
					mSleep = false;
235
      catch( ExitException e )
235
				}
236
      {
236
 
237
        mLogger.warn("run ExitException");
237
			} catch (SQLException e)
238
        exit = true;
238
			{
239
      }
239
				// oracle connection issues
240
      catch( InterruptedException e )
240
				mLogger.warn("run oracle connection issues");
241
      {
241
				mException = true;
242
        mLogger.warn("run InterruptedException");
242
			} catch (ExitException e)
243
      }
243
			{
244
      catch( Exception e )
244
				mLogger.warn("run ExitException");
245
      {
245
				exit = true;
246
        mLogger.error("run indefinitePause " + e.toString());
246
			} catch (InterruptedException e)
247
        String cause = e.getMessage();
247
			{
248
        if ( cause == null )
248
				mLogger.warn("run InterruptedException");
249
        {
249
			} catch (Exception e)
250
          cause = e.toString();
250
			{
251
        }
251
				mLogger.error("run indefinitePause " + e.toString());
252
                
252
				String cause = e.getMessage();
253
          try
253
				if (cause == null)
254
          {
254
				{
255
            // notify first
255
					cause = e.toString();
256
            // many reasons for indefinite pause, including database related, so do database last
256
				}
257
            mRecoverable = false;
257
 
258
            
258
				try
259
            if ( cause.compareTo(Package.mRecoverable) == 0 )
259
				{
260
            {
260
					// notify first
261
              mRecoverable = true;
261
					// many reasons for indefinite pause, including database
262
            }
262
					// related, so do database last
263
 
263
					mRecoverable = false;
264
            indefinitePause(rippleEngine, cause);
264
 
265
            mReleaseManager.indefinitePause();
265
					if (cause.compareTo(Package.mRecoverable) == 0)
266
            // DEVI 51366 force sleep at beginning of while loop
266
					{
267
            mException = true;
267
						mRecoverable = true;
268
          }
268
					}
269
          catch( Exception f )
269
 
270
          {
270
					indefinitePause(rippleEngine, cause);
271
            mLogger.error("run indefinitePause failed");
271
					mReleaseManager.indefinitePause();
272
          }
272
					// DEVI 51366 force sleep at beginning of while loop
273
        }
273
					mException = true;
274
      }
274
				} catch (Exception f)
275
    }
275
				{
276
 
276
					mLogger.error("run indefinitePause failed");
277
  /**returns 'S'
277
				}
278
   */
278
			}
279
  protected char getMode()
279
		}
280
  {
280
	}
281
    mLogger.debug("getMode");
281
 
282
    return 'S';
282
	/**
283
  }
283
	 * returns 'S'
-
 
284
	 */
-
 
285
	protected char getMode()
-
 
286
	{
-
 
287
		mLogger.debug("getMode");
-
 
288
		return 'S';
-
 
289
	}
284
}
290
}