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