| 6914 |
dpurdie |
1 |
package com.erggroup.buildtool.daemon;
|
|
|
2 |
|
|
|
3 |
import com.erggroup.buildtool.abt.BuildToolException;
|
|
|
4 |
import com.erggroup.buildtool.abt.RemoteExecution;
|
|
|
5 |
import com.erggroup.buildtool.abt.RemoteExecution.LogOutput;
|
|
|
6 |
import com.erggroup.buildtool.daemon.BuildThread;
|
|
|
7 |
import com.erggroup.buildtool.ripple.*;
|
|
|
8 |
import com.erggroup.buildtool.ripple.BuildFile.BuildFileState;
|
|
|
9 |
import com.erggroup.buildtool.ripple.Package;
|
|
|
10 |
import com.erggroup.buildtool.ripple.ReleaseManager.BuildResult;
|
|
|
11 |
import com.erggroup.buildtool.ripple.RunLevel.BuildState;
|
|
|
12 |
import com.erggroup.buildtool.smtp.CreateUrls;
|
|
|
13 |
import com.erggroup.buildtool.smtp.Smtpsend;
|
|
|
14 |
import com.erggroup.buildtool.utilities.*;
|
|
|
15 |
|
|
|
16 |
import java.io.BufferedReader;
|
|
|
17 |
import java.io.DataInputStream;
|
|
|
18 |
import java.io.File;
|
|
|
19 |
import java.io.FileInputStream;
|
|
|
20 |
import java.io.InputStreamReader;
|
|
|
21 |
import java.sql.SQLException;
|
|
|
22 |
import java.util.Iterator;
|
|
|
23 |
|
| 7033 |
dpurdie |
24 |
import org.slf4j.Logger;
|
|
|
25 |
import org.slf4j.LoggerFactory;
|
| 6914 |
dpurdie |
26 |
|
|
|
27 |
/**Master Thread sub component
|
|
|
28 |
*/
|
|
|
29 |
public class MasterThread extends BuildThread
|
|
|
30 |
{
|
|
|
31 |
|
|
|
32 |
/**Logger
|
|
|
33 |
* @attribute
|
|
|
34 |
*/
|
| 7033 |
dpurdie |
35 |
private static final Logger mLogger = LoggerFactory.getLogger(MasterThread.class);
|
| 6914 |
dpurdie |
36 |
|
|
|
37 |
/** Current BuildFile
|
|
|
38 |
*
|
|
|
39 |
*/
|
|
|
40 |
private BuildFile mMasterBuildFile = new BuildFile();
|
|
|
41 |
|
|
|
42 |
/** Measure the duration of the current build
|
|
|
43 |
*
|
|
|
44 |
*/
|
|
|
45 |
private ElapseTime mBuildDuration = new ElapseTime();
|
|
|
46 |
|
|
|
47 |
/**constructor
|
|
|
48 |
* @param rtagId - Identifies the Release
|
|
|
49 |
* @param rconId - Identifies the Controlling entry
|
|
|
50 |
* @param releaseManager - A ReleaseManager entry to use
|
|
|
51 |
* @param unitTest - Unit Test data
|
|
|
52 |
*/
|
|
|
53 |
public MasterThread(int rtagId, int rconId, ReleaseManager releaseManager, String unitTest)
|
|
|
54 |
{
|
|
|
55 |
super(rtagId, rconId, releaseManager, unitTest);
|
|
|
56 |
mLogger.warn("MasterThread rtag_id " + rtagId + " rcon_id " + rconId);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**implements the sequence diagrams coordinate slave threads, generate build files, allowed to proceed, check environment
|
|
|
60 |
*/
|
|
|
61 |
public void run()
|
|
|
62 |
{
|
|
|
63 |
Integer id = Integer.valueOf(mRtagId);
|
|
|
64 |
setName(id.toString());
|
|
|
65 |
mLogger.warn("Master Thread run");
|
|
|
66 |
boolean exit = false;
|
|
|
67 |
mRippleEngine = new RippleEngine(mReleaseManager, mRtagId, true);
|
|
|
68 |
|
|
|
69 |
while(!exit)
|
|
|
70 |
{
|
|
|
71 |
try
|
|
|
72 |
{
|
| 7033 |
dpurdie |
73 |
mLogger.error("run calling sleepCheck");
|
| 6914 |
dpurdie |
74 |
mPhase.setPhase("sleepCheck");
|
|
|
75 |
sleepCheck();
|
|
|
76 |
|
| 7033 |
dpurdie |
77 |
mLogger.error("run calling rippleEngine.collectMetaData");
|
| 6914 |
dpurdie |
78 |
mPhase.setPhase("collectMetaData", 600);
|
|
|
79 |
mRippleEngine.collectMetaData();
|
|
|
80 |
|
|
|
81 |
if ( Thread.currentThread().isInterrupted() )
|
|
|
82 |
{
|
|
|
83 |
mLogger.warn("run is interrupted");
|
|
|
84 |
// unit test technique
|
|
|
85 |
throw new ExitException();
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
if ( mUnitTest.compareTo("unit test spawn thread") == 0)
|
|
|
89 |
{
|
|
|
90 |
throw new Exception();
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
if ( !mUnitTest.startsWith("unit test check environment"))
|
|
|
94 |
{
|
|
|
95 |
if ( mUnitTest.compareTo("unit test generate build files") != 0)
|
|
|
96 |
{
|
|
|
97 |
if ((mUnitTest.compareTo("unit test allowed to proceed") != 0) &&
|
|
|
98 |
(mUnitTest.compareTo("unit test not allowed to proceed") != 0) &&
|
|
|
99 |
(mUnitTest.compareTo("unit test exit") != 0))
|
|
|
100 |
{
|
|
|
101 |
//---------------------------------------------------------------
|
|
|
102 |
// Wait for all Slaves to enter waiting or paused state
|
|
|
103 |
// They may be building
|
|
|
104 |
// They may be starting up
|
|
|
105 |
//
|
| 7033 |
dpurdie |
106 |
mLogger.error("run changing run level to WAITING (New) for rcon_id " + mRconId);
|
| 6914 |
dpurdie |
107 |
mPhase.setPhase("Wait for Slave Threads");
|
|
|
108 |
mRunLevel.persist(mReleaseManager, mRconId, BuildState.DB_WAITING);
|
|
|
109 |
|
|
|
110 |
while (true)
|
|
|
111 |
{
|
|
|
112 |
StringBuilder waitList = new StringBuilder();
|
|
|
113 |
mLogger.info("run calling mReleaseManager.queryRunLevel");
|
|
|
114 |
mReleaseManager.queryRunLevel(mRtagId);
|
|
|
115 |
|
|
|
116 |
// Process all run entries
|
|
|
117 |
|
|
|
118 |
for (Iterator<RunLevelData> it = mReleaseManager.mRunLevelCollection.iterator(); it.hasNext(); )
|
|
|
119 |
{
|
|
|
120 |
RunLevelData rl = it.next();
|
|
|
121 |
|
|
|
122 |
//
|
|
|
123 |
// Only examine Slaves.
|
|
|
124 |
// This is being run on a Master and at this point the Master is not waiting
|
|
|
125 |
// If there are multiple (misconfigured) Masters, then we can get confused
|
|
|
126 |
//
|
|
|
127 |
// If I am no longer a Master we will process till the end of the build cycle
|
|
|
128 |
// at which point it will be detected.
|
|
|
129 |
//
|
|
|
130 |
// If there are other Masters, then we assume that they are not waiting
|
|
|
131 |
//
|
|
|
132 |
|
|
|
133 |
// Ignore myself. I am not waiting. I am asking the questions
|
|
|
134 |
if ( rl.get_rcon_id() == mRconId) {
|
|
|
135 |
continue;
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
// Ignore other Master. They should not be waiting.
|
|
|
139 |
if ( rl.isMaster()) {
|
|
|
140 |
continue;
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
//
|
|
|
144 |
// A slave that is 'Paused' is not processing a package
|
|
|
145 |
// It will have been included in the build-set, so we must wait for
|
|
|
146 |
// the pause to be removed.
|
|
|
147 |
//
|
|
|
148 |
// A slave that is 'Waiting' must also have no BuildFile present
|
|
|
149 |
// This signals that the buildfile has been taken by the slave
|
|
|
150 |
//
|
|
|
151 |
if (! (rl.isAt(BuildState.DB_WAITING) && !rl.hasBuildFile() ) )
|
|
|
152 |
{
|
|
|
153 |
// A non-waiting slave has been found
|
|
|
154 |
waitList.append(" ");
|
|
|
155 |
waitList.append(rl.get_rcon_id());
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
if ( waitList.length() > 0 )
|
|
|
161 |
{
|
|
|
162 |
// One or more slaves still processing ...
|
|
|
163 |
if ( mUnitTest.compareTo("unit test coordinate slave threads") == 0 )
|
|
|
164 |
{
|
|
|
165 |
Thread.currentThread().interrupt();
|
|
|
166 |
}
|
|
|
167 |
else
|
|
|
168 |
{
|
|
|
169 |
|
|
|
170 |
mLogger.warn("Waiting 3 seconds for slaves:" + waitList.toString() );
|
|
|
171 |
Thread.sleep(3000);
|
|
|
172 |
mLogger.info("run sleep returned");
|
|
|
173 |
}
|
|
|
174 |
continue;
|
|
|
175 |
}
|
|
|
176 |
else
|
|
|
177 |
{
|
|
|
178 |
// All slaves have completed there tasks
|
|
|
179 |
break;
|
|
|
180 |
}
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
if ( mUnitTest.compareTo("unit test coordinate slave threads") == 0 )
|
|
|
184 |
{
|
|
|
185 |
throw new ExitException();
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
//---------------------------------------------------------------
|
|
|
189 |
// Publish Package Build Results
|
|
|
190 |
// Indicate to RM that we are publishing
|
|
|
191 |
// Ensure that all build machines have placed a marker in dpkg_archive
|
|
|
192 |
// Save updated build files into VCS
|
|
|
193 |
//
|
| 7033 |
dpurdie |
194 |
mLogger.error("run changing run level to PUBLISHING for rcon_id " + mRconId);
|
| 6914 |
dpurdie |
195 |
mPhase.setPhase("Publishing");
|
|
|
196 |
mRunLevel.persist(mReleaseManager, mRconId, BuildState.DB_PUBLISHING);
|
|
|
197 |
|
|
|
198 |
mLogger.info("run calling deliverChange on AbtPublish");
|
|
|
199 |
deliverChange("AbtPublish", true, false);
|
|
|
200 |
|
|
|
201 |
//---------------------------------------------------------------
|
|
|
202 |
// TearDown the build workspace
|
|
|
203 |
// Remove the build workspace
|
|
|
204 |
// Save build log files
|
|
|
205 |
// Don't update the Reporting Information as it will null out
|
|
|
206 |
// some essential information that has been collected.
|
|
|
207 |
//
|
|
|
208 |
mLogger.info("run calling deliverChange on AbtTearDown");
|
|
|
209 |
mPhase.setPhase("AbtTearDown");
|
|
|
210 |
deliverChange("AbtTearDown", false, true);
|
|
|
211 |
|
|
|
212 |
// Delete the build file now
|
|
|
213 |
// This will prevent any chance of multiply publishing a package version
|
|
|
214 |
deleteBuildFile();
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
//---------------------------------------------------------------
|
|
|
218 |
// Update Release Manager (publish to Release Manager)
|
|
|
219 |
//
|
|
|
220 |
mPhase.setPhase("Update Release Manager");
|
|
|
221 |
if ( mReporting.packageName != null )
|
|
|
222 |
{
|
|
|
223 |
// A dummy build file did not apply
|
|
|
224 |
// Publishing is done outside ant by design
|
|
|
225 |
// Do ALL Release Manager work outside ant (and JATS)
|
|
|
226 |
|
|
|
227 |
boolean buildErrorOccurred = true;
|
|
|
228 |
boolean publishError = true;
|
|
|
229 |
|
|
|
230 |
try
|
|
|
231 |
{
|
|
|
232 |
// Create a build instance entry in the Release Manager database
|
|
|
233 |
// Create one per build
|
|
|
234 |
// mReporting.packageVersionId will have been updated if this is a new package-version
|
|
|
235 |
// Save the build id
|
|
|
236 |
mPhase.setPhase("Create Build Instance");
|
|
|
237 |
mReporting.buildId = mReleaseManager.createBuildInstance(
|
|
|
238 |
mRtagId,
|
|
|
239 |
mReporting.packageVersionId,
|
|
|
240 |
mReporting.buildReason );
|
|
|
241 |
//
|
|
|
242 |
// Locate and collect the unit test results
|
|
|
243 |
//
|
|
|
244 |
mPhase.setPhase("Parse Unit Test Results");
|
|
|
245 |
BuildTestResults btr = new BuildTestResults(System.getenv("GBE_DPKG"), mReporting, mLogger);
|
|
|
246 |
mReleaseManager.insertTestResults(mReporting.buildId, btr);
|
|
|
247 |
|
|
|
248 |
if ( mReporting.isaTestBuild )
|
|
|
249 |
{
|
|
|
250 |
|
|
|
251 |
// Test Build
|
|
|
252 |
// Notify the user requesting the build
|
|
|
253 |
// Build Failure emails have already been sent
|
|
|
254 |
//
|
|
|
255 |
mLogger.info("run completing test build on " + mReporting.packageName + mReporting.packageExtension);
|
|
|
256 |
mPhase.setPhase("Report Test Build Complete");
|
|
|
257 |
Package p = mRippleEngine.findPackage(mReporting.packageName + mReporting.packageExtension);
|
|
|
258 |
if (p != ReleaseManager.NULL_PACKAGE)
|
|
|
259 |
{
|
| 7033 |
dpurdie |
260 |
mLogger.error("run calling p.completeTestBuild");
|
| 6914 |
dpurdie |
261 |
p.completeTestBuild(mRippleEngine, mReporting.isFullyPublished);
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
//
|
|
|
265 |
// Determine the total time taken by the build
|
|
|
266 |
// Done as late a possible in the process
|
|
|
267 |
// Does not include planning time
|
|
|
268 |
// Does not handle case where build cycle is broken
|
|
|
269 |
// Only record for successful tests. Don't want to record short build times on failure
|
|
|
270 |
// in particular if the package has been released. Would be OK for a WIP, but how to identify these
|
|
|
271 |
if ( mReporting.isFullyPublished)
|
|
|
272 |
{
|
|
|
273 |
int buildDuration = mBuildDuration.toIntSecs();
|
| 7033 |
dpurdie |
274 |
mLogger.error("Build Duration:" + buildDuration);
|
| 6914 |
dpurdie |
275 |
mReleaseManager.updateBuildDuration(mReporting.packageVersionId, buildDuration);
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
mPhase.setPhase("Update Build Instance for Test");
|
|
|
279 |
mReleaseManager.updateBuildInstance(mReporting.buildId, 0, mReporting.isFullyPublished ? BuildResult.Complete :BuildResult.BuildError );
|
|
|
280 |
|
|
|
281 |
// ... and clean up the mess in the archive
|
|
|
282 |
publishError = false;
|
|
|
283 |
throw new Exception();
|
|
|
284 |
}
|
|
|
285 |
|
|
|
286 |
// Package not fully published
|
|
|
287 |
// An error has occurred in the building of the package
|
|
|
288 |
if ( !mReporting.isFullyPublished )
|
|
|
289 |
{
|
|
|
290 |
mLogger.info("run build error occurred on " + mReporting.packageName + mReporting.packageVersion);
|
|
|
291 |
|
|
|
292 |
// ... and clean up the mess in the archive
|
|
|
293 |
publishError = false;
|
|
|
294 |
throw new Exception();
|
|
|
295 |
}
|
|
|
296 |
|
|
|
297 |
//---------------------------------------------------------------
|
|
|
298 |
// Package was successfully built and published into dpkg_archive by all daemons
|
|
|
299 |
// Update Release Manager - formally release the package
|
|
|
300 |
// Insert Package Metrics
|
|
|
301 |
// Insert Unit Test Results
|
|
|
302 |
buildErrorOccurred = false;
|
|
|
303 |
|
|
|
304 |
//
|
|
|
305 |
// Detect Badly formed VCS label returned by the builder
|
|
|
306 |
// Have had zero length values returned
|
|
|
307 |
// Treat as a publishing error
|
|
|
308 |
//
|
|
|
309 |
if ( mReporting.newVcsTag == null || mReporting.newVcsTag.isEmpty() )
|
|
|
310 |
{
|
| 7033 |
dpurdie |
311 |
mLogger.error("run package not labelled in Version Control on " + mReporting.packageName + mReporting.packageVersion);
|
| 6914 |
dpurdie |
312 |
mReporting.errMsg = "Error publishing to Version Control System"; // Max 50 Characters
|
|
|
313 |
throw new Exception();
|
|
|
314 |
}
|
|
|
315 |
|
|
|
316 |
|
|
|
317 |
// Publish to release manager
|
|
|
318 |
// On error mReporting.errMsg will contain error string
|
|
|
319 |
// Publishing errors only affect the current package
|
|
|
320 |
//
|
| 7033 |
dpurdie |
321 |
mLogger.error("run calling mReleaseManager.autoMakeRelease");
|
| 6914 |
dpurdie |
322 |
mPhase.setPhase("autoMakeRelease");
|
|
|
323 |
publishError = mReleaseManager.autoMakeRelease(mReporting);
|
|
|
324 |
if ( publishError )
|
|
|
325 |
{
|
| 7033 |
dpurdie |
326 |
mLogger.error("autoMakeRelease publishError: " + mReporting.errMsg);
|
| 6914 |
dpurdie |
327 |
throw new Exception();
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
//
|
|
|
331 |
// Determine the total time taken by the build
|
|
|
332 |
// Done as late a possible in the process
|
|
|
333 |
// Does not include planning time
|
|
|
334 |
// Does not handle case where build cycle is broken
|
|
|
335 |
//
|
|
|
336 |
int buildDuration = mBuildDuration.toIntSecs();
|
| 7033 |
dpurdie |
337 |
mLogger.error("Build Duration:" + buildDuration);
|
| 6914 |
dpurdie |
338 |
mReleaseManager.updateBuildDuration(mReporting.packageVersionId, buildDuration);
|
|
|
339 |
|
|
|
340 |
//
|
|
|
341 |
// Update the Build Instance information
|
|
|
342 |
// If this has been a ripple then the pv_id of the build needs to be associated with
|
|
|
343 |
// the newly created version
|
|
|
344 |
|
|
|
345 |
mPhase.setPhase("Update Build Instance");
|
|
|
346 |
mReleaseManager.updateBuildInstance(mReporting.buildId, mReporting.packageVersionId, BuildResult.Complete );
|
|
|
347 |
|
|
|
348 |
//
|
|
|
349 |
// Insert package metrics into Release Manager
|
|
|
350 |
// Metrics have been placed in a file in a format suitable for RM
|
|
|
351 |
//
|
|
|
352 |
mReporting.errMsg = "Error publishing Package Metrics"; // Max 50 Characters
|
|
|
353 |
mPhase.setPhase("Insert Metrics");
|
|
|
354 |
FileInputStream abtmetrics = new FileInputStream( String.valueOf(mRtagId) + "abtmetrics.txt" );
|
|
|
355 |
DataInputStream din = new DataInputStream( abtmetrics );
|
|
|
356 |
InputStreamReader isr = new InputStreamReader( din );
|
|
|
357 |
BufferedReader br = new BufferedReader( isr );
|
|
|
358 |
String metrics = br.readLine();
|
|
|
359 |
mLogger.warn( "execute read metrics string " + metrics );
|
|
|
360 |
br.close();
|
|
|
361 |
isr.close();
|
|
|
362 |
din.close();
|
|
|
363 |
|
| 7033 |
dpurdie |
364 |
mLogger.error("run calling mReleaseManager.insertPackageMetrics");
|
| 6914 |
dpurdie |
365 |
mReleaseManager.insertPackageMetrics(mRtagId, mReporting.packageName, mReporting.packageExtension, metrics );
|
|
|
366 |
|
|
|
367 |
//
|
|
|
368 |
// Info reporting
|
|
|
369 |
// Send an email to track build system usage - may be noise
|
|
|
370 |
//
|
|
|
371 |
mReporting.errMsg = null;
|
| 7033 |
dpurdie |
372 |
mLogger.error("run calling emailBuildComplete");
|
| 6914 |
dpurdie |
373 |
mPhase.setPhase("Post Build Email");
|
|
|
374 |
emailPostBuild(mRippleEngine, false);
|
|
|
375 |
|
|
|
376 |
//---------------------------------------------------------------
|
|
|
377 |
// All done
|
|
|
378 |
// The package has been built and released
|
|
|
379 |
mPhase.setPhase("Build Complete");
|
|
|
380 |
}
|
|
|
381 |
catch( Exception e)
|
|
|
382 |
{
|
|
|
383 |
// Some form of error has occurred. Types include
|
|
|
384 |
// Test build (Treated as an error so that dpkg_archive gets removed)
|
|
|
385 |
// buildErrorOccurred - True
|
|
|
386 |
// publishError - False
|
|
|
387 |
// Build Error - Package was not fully published to dpkg_archive
|
|
|
388 |
// buildErrorOccurred - True
|
|
|
389 |
// publishError - False
|
|
|
390 |
//
|
|
|
391 |
// Badly formed VCS tag (Error Publishing to Version Control)
|
|
|
392 |
// buildErrorOccurred - False
|
|
|
393 |
// publishError - True
|
|
|
394 |
// Error Publishing to Release Manager
|
|
|
395 |
// buildErrorOccurred - False
|
|
|
396 |
// publishError - True
|
|
|
397 |
// Error inserting package metrics
|
|
|
398 |
// buildErrorOccurred - False
|
|
|
399 |
// publishError - True
|
|
|
400 |
// Error inserting unit test results
|
|
|
401 |
// buildErrorOccurred - False
|
|
|
402 |
// publishError - True
|
|
|
403 |
//
|
|
|
404 |
// Uses
|
|
|
405 |
// buildErrorOccurred - Package not in dpkg_archive as expected (or was a test build)
|
|
|
406 |
// Email should have been sent to the user
|
|
|
407 |
// publishError - Could not publish to Release Manager
|
|
|
408 |
// Post build error. Email has not been sent to user
|
|
|
409 |
// Takes precedence over buildErrorOccurred
|
|
|
410 |
|
|
|
411 |
// Insert generic message if we don't have one
|
|
|
412 |
// Should only occur under unexpected conditions
|
|
|
413 |
if (mReporting.errMsg == null || mReporting.errMsg.isEmpty())
|
|
|
414 |
{
|
|
|
415 |
mReporting.errMsg = "Error publishing to Release Manager";
|
|
|
416 |
mReporting.errMsgDetail = mPhase.sText;
|
|
|
417 |
}
|
|
|
418 |
|
|
|
419 |
// Indicate some form of build error
|
|
|
420 |
if ( ! mReporting.isaTestBuild )
|
|
|
421 |
{
|
|
|
422 |
mPhase.setPhase("Update Build Instance");
|
|
|
423 |
mReleaseManager.updateBuildInstance(mReporting.buildId, 0, publishError ? BuildResult.SystemError :BuildResult.BuildError );
|
|
|
424 |
}
|
|
|
425 |
|
|
|
426 |
//
|
|
|
427 |
// Delete the dpkg_archive entry - the package is a dud
|
|
|
428 |
//
|
|
|
429 |
mPhase.setPhase("Delete package from archive");
|
| 7033 |
dpurdie |
430 |
mLogger.error("Delete package from archive");
|
| 6914 |
dpurdie |
431 |
deletePackageVersion();
|
|
|
432 |
|
|
|
433 |
// A publishing error. The error occurred, after the build, in the RM publishing
|
|
|
434 |
// We won't have a log file, but we will have a rootCause
|
|
|
435 |
// Exclude package from the build
|
|
|
436 |
// Unless its a test build (handled within mReleaseManager.excludeFromBuild)
|
|
|
437 |
//
|
|
|
438 |
if ( publishError )
|
|
|
439 |
{
|
| 7033 |
dpurdie |
440 |
mLogger.error("an error occurred publishing to Version Control or Release Manager");
|
| 6914 |
dpurdie |
441 |
|
|
|
442 |
// Post Build Error
|
|
|
443 |
// eMails have not been sent by the ABT class as the error has occurred outside of that process
|
|
|
444 |
mPhase.setPhase("Post Build Failure Email");
|
|
|
445 |
emailPostBuild(mRippleEngine, true);
|
|
|
446 |
|
| 7033 |
dpurdie |
447 |
mLogger.error("run calling excludeFromBuild");
|
| 6914 |
dpurdie |
448 |
mPhase.setPhase("Excluded from build");
|
|
|
449 |
mReleaseManager.excludeFromBuild(false,
|
|
|
450 |
mReporting.packageVersionId,
|
|
|
451 |
null,
|
|
|
452 |
mReporting.rtagId,
|
|
|
453 |
null,
|
|
|
454 |
mReporting.errMsg,
|
|
|
455 |
null,
|
|
|
456 |
false, mReporting.isaTestBuild);
|
|
|
457 |
|
|
|
458 |
}
|
|
|
459 |
else if ( buildErrorOccurred )
|
|
|
460 |
{
|
|
|
461 |
// Build Error Occurred
|
|
|
462 |
// Package has not been built on all configured platforms
|
|
|
463 |
// Under normal circumstances, this root cause will be masked by a previously reported error
|
|
|
464 |
// Under abnormal circumstances amidst build activity such as:
|
|
|
465 |
// - slave build machine reboots
|
|
|
466 |
// - slave build machines with a read only file system
|
|
|
467 |
// The rootCause is required to keep the end user informed
|
|
|
468 |
//
|
|
|
469 |
// Use excludeFromBuild such that this call will not supersede existing entries
|
|
|
470 |
// In this manner the log file/cause provided here will only be used if we haven't
|
|
|
471 |
// already excluded this package from the build
|
|
|
472 |
|
|
|
473 |
// If we have a log file, then provide it to the user, else insert a generic message
|
|
|
474 |
|
|
|
475 |
mReporting.errMsg = (mReporting.buildFailureLogFile == null) ? "Buildtool env error occurred. Attempt build again" : null;
|
|
|
476 |
|
| 7033 |
dpurdie |
477 |
mLogger.error("run calling excludeFromBuild");
|
| 6914 |
dpurdie |
478 |
mPhase.setPhase("Excluded from build");
|
|
|
479 |
mReleaseManager.excludeFromBuild(false,
|
|
|
480 |
mReporting.packageVersionId,
|
|
|
481 |
mReporting.packageVersion,
|
|
|
482 |
mReporting.rtagId,
|
|
|
483 |
null,
|
|
|
484 |
mReporting.errMsg,
|
|
|
485 |
mReporting.buildFailureLogFile,
|
|
|
486 |
false, mReporting.isaTestBuild);
|
|
|
487 |
}
|
|
|
488 |
else
|
|
|
489 |
{
|
|
|
490 |
// Not a buildError and not a publishing Error
|
|
|
491 |
// Don't know how we got here - I don't think we can
|
|
|
492 |
// Will cause an indefinite pause !
|
|
|
493 |
throw new Exception("an error occurred publishing to Version Control or Release Manager");
|
|
|
494 |
|
|
|
495 |
}
|
|
|
496 |
} // End Catch
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
if ( mUnitTest.compareTo("unit test coordinate slave threads") == 0 )
|
|
|
500 |
{
|
|
|
501 |
throw new ExitException();
|
|
|
502 |
}
|
|
|
503 |
mLogger.info("run coordinate slave threads returned");
|
|
|
504 |
}
|
|
|
505 |
|
|
|
506 |
|
|
|
507 |
//---------------------------------------------------------------
|
|
|
508 |
// Start of a new build cycle
|
|
|
509 |
// Determine if the daemon has been paused.
|
|
|
510 |
// Set RunLevel.IDLE (within allowedToProceed)
|
|
|
511 |
//
|
| 7033 |
dpurdie |
512 |
mLogger.error("run calling allowedToProceed");
|
| 6914 |
dpurdie |
513 |
mPhase.setPhase("allowedToProceed");
|
|
|
514 |
mReleaseManager.discardVersion();
|
|
|
515 |
mReleaseManager.clearCurrentPackageBeingBuilt(mRconId);
|
|
|
516 |
allowedToProceed(true);
|
|
|
517 |
mLogger.info("run allowedToProceed returned");
|
|
|
518 |
|
|
|
519 |
if ( mUnitTest.compareTo("unit test allowed to proceed") == 0 )
|
|
|
520 |
{
|
|
|
521 |
throw new ExitException();
|
|
|
522 |
}
|
|
|
523 |
|
|
|
524 |
// Set up mReleaseConfigCollection
|
|
|
525 |
// This will be used when creating a build file
|
| 7033 |
dpurdie |
526 |
mLogger.error("Collect fresh MetaData");
|
| 6914 |
dpurdie |
527 |
mPhase.setPhase("collectMetaData");
|
|
|
528 |
mRippleEngine.collectMetaData();
|
|
|
529 |
|
|
|
530 |
//---------------------------------------------------------------
|
|
|
531 |
// Plan the next build
|
|
|
532 |
// Snap current Release Sequence Number
|
|
|
533 |
// Determine what is to be built
|
|
|
534 |
// Generate build files
|
| 7033 |
dpurdie |
535 |
mLogger.error("run calling planRelease");
|
| 6914 |
dpurdie |
536 |
mPhase.setPhase("Plan Release", 600);
|
|
|
537 |
mReleaseSeqNum = mReleaseManager.queryReleaseSeqNum(mRtagId, mRconId, BuildDaemon.mHostname);
|
|
|
538 |
mRippleEngine.planRelease(!mLastBuildWasBenign);
|
|
|
539 |
|
|
|
540 |
// get the build file from the ripple engine
|
|
|
541 |
mPhase.setPhase("Get Build File", 10);
|
|
|
542 |
mMasterBuildFile = mRippleEngine.getFirstBuildFileContent();
|
|
|
543 |
|
|
|
544 |
}
|
|
|
545 |
}
|
|
|
546 |
|
|
|
547 |
//---------------------------------------------------------------
|
|
|
548 |
// Check that we are good to proceed with the build
|
|
|
549 |
// Check environment
|
|
|
550 |
// Ensure we have enough disk space
|
|
|
551 |
//
|
| 7033 |
dpurdie |
552 |
mLogger.error("run calling checkEnvironment");
|
| 6914 |
dpurdie |
553 |
mPhase.setPhase("checkEnvironment");
|
|
|
554 |
checkEnvironment();
|
|
|
555 |
mLogger.info("run checkEnvironment returned");
|
|
|
556 |
|
|
|
557 |
if ( mUnitTest.startsWith("unit test check environment") )
|
|
|
558 |
{
|
|
|
559 |
throw new ExitException();
|
|
|
560 |
}
|
|
|
561 |
|
|
|
562 |
mLogger.info("run generated build files");
|
|
|
563 |
// Start of a build cycle. Set new log file to capture entire build log
|
|
|
564 |
mPhase.setPhase("Start Build Cycle");
|
|
|
565 |
flagStartBuildCycle();
|
|
|
566 |
mBuildDuration.reset();
|
|
|
567 |
mReporting.resetData();
|
|
|
568 |
mRunLevel.persist(mReleaseManager, mRconId, BuildState.DB_ACTIVE);
|
|
|
569 |
mReleaseManager.setCurrentPackageBeingBuilt(mRconId, mMasterBuildFile.mPkgId, mMasterBuildFile.mPvId);
|
|
|
570 |
|
|
|
571 |
// Save the buildfile
|
| 7033 |
dpurdie |
572 |
mLogger.error("Save buildfile");
|
| 6914 |
dpurdie |
573 |
mPhase.setPhase("Save buildfile");
|
|
|
574 |
saveBuildFile(mMasterBuildFile.content);
|
|
|
575 |
|
|
|
576 |
// Quick Test to validate the provided Version Control tag/label
|
|
|
577 |
mPhase.setPhase("Validate Version Tag");
|
|
|
578 |
if ( deliverChange("AbtTestPath", true, false) )
|
|
|
579 |
{
|
|
|
580 |
|
|
|
581 |
//---------------------------------------------------------------
|
|
|
582 |
// Notify all slaves that there is work to be done
|
|
|
583 |
// This is done by publishing a buildfile for them to consume
|
|
|
584 |
// A NonGeneric build will be done with a real build file on all machines
|
|
|
585 |
// Otherwise do a Dummy build on all Machines
|
|
|
586 |
//
|
|
|
587 |
mPhase.setPhase("Notify slaves of work", 10);
|
|
|
588 |
if ( mMasterBuildFile.state != BuildFileState.NonGeneric)
|
|
|
589 |
{
|
|
|
590 |
// publish a dummy build file for either generic or dummy cases
|
|
|
591 |
// this results in the slave not running ant
|
| 7033 |
dpurdie |
592 |
mLogger.error("run calling publishBuildFile on dummy");
|
| 6914 |
dpurdie |
593 |
mMasterBuildFile.content = mDummyBuildFileContent;
|
|
|
594 |
}
|
|
|
595 |
else
|
|
|
596 |
{
|
|
|
597 |
// publish the build file
|
| 7033 |
dpurdie |
598 |
mLogger.error("run calling publishBuildFile");
|
| 6914 |
dpurdie |
599 |
}
|
|
|
600 |
mReleaseManager.publishBuildFile(mRtagId, mMasterBuildFile);
|
|
|
601 |
|
|
|
602 |
|
|
|
603 |
if ( mUnitTest.compareTo("unit test generate build files") == 0 )
|
|
|
604 |
{
|
|
|
605 |
throw new ExitException();
|
|
|
606 |
}
|
|
|
607 |
|
|
|
608 |
mLogger.info("run changed run levels");
|
|
|
609 |
|
|
|
610 |
//---------------------------------------------------------------
|
|
|
611 |
// Build the package
|
|
|
612 |
// Setup the workspace
|
|
|
613 |
// Build the package - deliver change to product baseline
|
|
|
614 |
//
|
| 7033 |
dpurdie |
615 |
mLogger.error("Build Package " + mReporting.packageName + "_" + mReporting.packageVersion);
|
| 6914 |
dpurdie |
616 |
|
|
|
617 |
mLogger.info("run calling setViewUp");
|
|
|
618 |
mPhase.setPhase("Setup View for build");
|
|
|
619 |
deliverChange("AbtSetUp", true, false);
|
|
|
620 |
|
|
|
621 |
mLogger.info("run calling deliverChange - the actual build");
|
|
|
622 |
mPhase.setPhase("Build Package");
|
|
|
623 |
deliverChange(null, true, false);
|
|
|
624 |
mLogger.info("run deliverChange returned");
|
|
|
625 |
}
|
|
|
626 |
|
|
|
627 |
mLastBuildWasBenign = false;
|
|
|
628 |
if ( mMasterBuildFile.state == BuildFileState.Dummy)
|
|
|
629 |
{
|
|
|
630 |
// no build requirement, so let things settle
|
|
|
631 |
mLogger.warn("run no build requirement, so let things settle");
|
|
|
632 |
mLastBuildWasBenign = true;
|
|
|
633 |
}
|
|
|
634 |
}
|
|
|
635 |
//---------------------------------------------------------------
|
|
|
636 |
// Build loop exception handling (only)
|
|
|
637 |
//
|
|
|
638 |
catch( SQLException e )
|
|
|
639 |
{
|
|
|
640 |
// Oracle connection issues
|
|
|
641 |
// Request a prolonged sleep at the start of the build loop
|
| 7033 |
dpurdie |
642 |
mLogger.error("run oracle connection issues");
|
| 6914 |
dpurdie |
643 |
mException = true;
|
|
|
644 |
}
|
|
|
645 |
catch( ExitException e )
|
|
|
646 |
{
|
|
|
647 |
mLogger.warn("run ExitException");
|
|
|
648 |
exit = true;
|
|
|
649 |
}
|
|
|
650 |
catch( InterruptedException e )
|
|
|
651 |
{
|
|
|
652 |
mLogger.warn("run InterruptedException");
|
|
|
653 |
Thread.currentThread().interrupt();
|
|
|
654 |
}
|
|
|
655 |
catch (BuildSystemException e) {
|
|
|
656 |
// BuildSystem exception - a (possibly) correctable error
|
|
|
657 |
// Flag as recoverable
|
|
|
658 |
// - Can't create XML build file
|
|
|
659 |
// -
|
|
|
660 |
//
|
| 7033 |
dpurdie |
661 |
mLogger.error("run BuildSystemException");
|
| 6914 |
dpurdie |
662 |
mPhase.setPhase("BuildSystemException indefinitePause");
|
|
|
663 |
notifyIndefinitePause(e.getMessage());
|
|
|
664 |
mReleaseManager.indefinitePause(false);
|
|
|
665 |
mException = true;
|
|
|
666 |
mRecoverable = true;
|
|
|
667 |
|
|
|
668 |
}
|
|
|
669 |
catch( BuildToolException e)
|
|
|
670 |
{
|
|
|
671 |
// Buildtool exception - an uncorrectable error
|
|
|
672 |
// - Can't parse XML build file
|
|
|
673 |
//
|
| 7033 |
dpurdie |
674 |
mLogger.error("run BuildToolException");
|
| 6914 |
dpurdie |
675 |
mPhase.setPhase("BuildToolException indefinitePause");
|
|
|
676 |
notifyIndefinitePause(e.getMessage());
|
|
|
677 |
mReleaseManager.indefinitePause(false);
|
|
|
678 |
mException = true;
|
|
|
679 |
}
|
|
|
680 |
catch( Exception e )
|
|
|
681 |
{
|
|
|
682 |
// Uncaptured exception
|
|
|
683 |
// These are not good. Current mechanism to handle this condition is:
|
|
|
684 |
// 1) Email build system administrator
|
|
|
685 |
// 2) Pause the build system
|
|
|
686 |
//
|
|
|
687 |
mLogger.error("run indefinitePause " + e.toString());
|
|
|
688 |
|
|
|
689 |
// DEVI 51366 force sleep at beginning of while loop
|
|
|
690 |
mException = true;
|
|
|
691 |
|
|
|
692 |
String cause = e.getMessage();
|
|
|
693 |
if ( cause == null || cause.compareTo("null") == 0 )
|
|
|
694 |
{
|
|
|
695 |
cause = "Internal Error: " + e.toString();
|
|
|
696 |
}
|
|
|
697 |
|
|
|
698 |
try
|
|
|
699 |
{
|
|
|
700 |
// notify first
|
|
|
701 |
// many reasons for indefinite pause, including database related, so do database last
|
|
|
702 |
mRecoverable = false;
|
|
|
703 |
|
|
|
704 |
if ( cause.compareTo(Package.mRecoverable) == 0 )
|
|
|
705 |
{
|
|
|
706 |
mRecoverable = true;
|
|
|
707 |
}
|
|
|
708 |
|
|
|
709 |
mPhase.setPhase("Notify indefinitePause");
|
|
|
710 |
notifyIndefinitePause(cause);
|
|
|
711 |
mReleaseManager.indefinitePause(mRecoverable);
|
|
|
712 |
mReleaseManager.updateBuildInstance(mReporting.buildId, 0, BuildResult.SystemError );
|
|
|
713 |
}
|
|
|
714 |
catch( Exception f )
|
|
|
715 |
{
|
|
|
716 |
mLogger.error("run indefinitePause failed");
|
|
|
717 |
}
|
|
|
718 |
}
|
|
|
719 |
}
|
|
|
720 |
try {
|
|
|
721 |
mReleaseManager.clearCurrentPackageBeingBuilt(mRconId);
|
|
|
722 |
} catch (Exception e) {
|
|
|
723 |
mLogger.error("Exception in clearCurrentPackageBeingBuilt:" + e.getMessage());
|
|
|
724 |
}
|
|
|
725 |
mPhase.setPhase("Exit Thread");
|
|
|
726 |
}
|
|
|
727 |
|
|
|
728 |
/** Delete a specified version of a package from dpkg_archive
|
|
|
729 |
* Used during error processing to cleanup packages that did not build correctly
|
|
|
730 |
*
|
|
|
731 |
* The package-version is in dpkg_archive. This may be on a remote server
|
|
|
732 |
* Execute the deletion command on the remote server as it will be a lot faster
|
|
|
733 |
* for large packages.
|
|
|
734 |
*
|
|
|
735 |
* Ensure that the file system cache is cleared before we attempt to look
|
|
|
736 |
* for the directory
|
|
|
737 |
*/
|
|
|
738 |
private void deletePackageVersion()
|
|
|
739 |
{
|
|
|
740 |
|
|
|
741 |
// Setup a Remote Execution environment
|
|
|
742 |
// The logging interface is is hard part
|
|
|
743 |
RemoteExecution mRemoteExecution = new RemoteExecution(new LogOutput(){
|
|
|
744 |
|
|
|
745 |
@Override
|
|
|
746 |
public void data(String message) {
|
|
|
747 |
mLogger.info(message);
|
|
|
748 |
}
|
|
|
749 |
|
|
|
750 |
@Override
|
|
|
751 |
public void fatal(String message) {
|
| 7033 |
dpurdie |
752 |
mLogger.error(message);
|
| 6914 |
dpurdie |
753 |
}
|
|
|
754 |
|
|
|
755 |
@Override
|
|
|
756 |
public void info(String message) {
|
|
|
757 |
mLogger.info(message);
|
|
|
758 |
}});
|
|
|
759 |
|
|
|
760 |
|
|
|
761 |
// Execute the remote command
|
|
|
762 |
// This is a best effort deletion - can't really handle conditions
|
|
|
763 |
// where the command fails.
|
|
|
764 |
CommandBuilder cmd = new CommandBuilder();
|
|
|
765 |
|
|
|
766 |
cmd.add("sudo","-n", "-u", "buildadm", "/home/releasem/sbin/jatsTool", "assemble_dpkg");
|
|
|
767 |
cmd.add("-DeleteVersion");
|
|
|
768 |
cmd.add(!ReleaseManager.getUseMutex(), "-testArchive");
|
|
|
769 |
cmd.add("'-pname=" + mReporting.packageName + "'");
|
|
|
770 |
cmd.add("'-pversion=" + mReporting.packageVersion + "'");
|
|
|
771 |
|
| 7033 |
dpurdie |
772 |
mLogger.error("run remote command to delete " + mReporting.packageName +", "+ mReporting.packageVersion);
|
| 6914 |
dpurdie |
773 |
int rv = mRemoteExecution.execute(cmd.toString());
|
| 7033 |
dpurdie |
774 |
mLogger.error("run remote command to delete. Returned " + rv);
|
| 6914 |
dpurdie |
775 |
|
|
|
776 |
// Belt and Braces
|
|
|
777 |
// Ensure that the package-version has been deleted,
|
|
|
778 |
// and if not then try to delete it the slow way.
|
|
|
779 |
//
|
|
|
780 |
// Note: Need to flush NFS cache before we check existence
|
|
|
781 |
|
|
|
782 |
String dpkgArchiveEntry = utilities.catDir(Package.mGbeDpkg, mReporting.packageName, mReporting.packageVersion);
|
|
|
783 |
File dpkgArchiveEntryFile = utilities.freshFile(dpkgArchiveEntry);
|
|
|
784 |
mLogger.info("run checking existence of " + dpkgArchiveEntry);
|
|
|
785 |
|
|
|
786 |
if ( dpkgArchiveEntryFile.exists() )
|
|
|
787 |
{
|
|
|
788 |
if ( dpkgArchiveEntryFile.isDirectory() )
|
|
|
789 |
{
|
| 7033 |
dpurdie |
790 |
mLogger.error("run calling deleteDirectory on " + dpkgArchiveEntryFile);
|
| 6914 |
dpurdie |
791 |
deleteDirectory(dpkgArchiveEntryFile);
|
|
|
792 |
}
|
|
|
793 |
}
|
|
|
794 |
}
|
|
|
795 |
|
|
|
796 |
/** Sends email notification and mark the successful completion of a build
|
|
|
797 |
* Used simply to keep an email trail of build operations
|
|
|
798 |
*/
|
|
|
799 |
public void emailPostBuild( RippleEngine rippleEngine, boolean isaError )
|
|
|
800 |
{
|
|
|
801 |
mLogger.debug("emailPostBuild");
|
|
|
802 |
String subject;
|
|
|
803 |
String emailTo;
|
|
|
804 |
String mailBody = "";
|
|
|
805 |
|
|
|
806 |
if (isaError)
|
|
|
807 |
{
|
|
|
808 |
subject = "BUILD FAILURE on package " + mReporting.packageName + " " + mReporting.packageVersion;
|
|
|
809 |
emailTo = mReporting.packageOwners;
|
|
|
810 |
mailBody="An error occured within the build system after the package had been built<p><hr>";
|
|
|
811 |
}
|
|
|
812 |
else
|
|
|
813 |
{
|
|
|
814 |
subject = "BUILD SUCCESS on package " + mReporting.packageName + " " + mReporting.packageVersion;
|
|
|
815 |
emailTo = rippleEngine.getMailSender();
|
|
|
816 |
}
|
|
|
817 |
|
|
|
818 |
// Cleanup the dependency string
|
|
|
819 |
// Expecting: 'junit','3.7.0.cots';'ant-ejbdoclet','1.0000.cr'
|
|
|
820 |
String indent = "<br> ";
|
|
|
821 |
String depends = mReporting.packageDepends.replace("','", " ");
|
|
|
822 |
depends = depends.replace("';'",indent);
|
|
|
823 |
depends = depends.replace("'","");
|
|
|
824 |
|
|
|
825 |
// Cleanup the build standard string
|
|
|
826 |
// Expecting win32: jats all;linux_i386: jats prod
|
|
|
827 |
String buildStandards = mReporting.packageBuildInfo;
|
|
|
828 |
buildStandards = buildStandards.replace(";",indent);
|
|
|
829 |
|
|
|
830 |
mailBody += "Release : " + rippleEngine.mBaselineName + "<br>" +
|
|
|
831 |
"Package : " + mReporting.packageName + "<br>" +
|
|
|
832 |
"Version : " + mReporting.packageVersion + "<br>";
|
|
|
833 |
if (isaError)
|
|
|
834 |
{
|
|
|
835 |
mailBody += "Cause : " + mReporting.errMsg + "<br>";
|
|
|
836 |
if (mReporting.errMsgDetail != null && mReporting.errMsgDetail.length() > 0)
|
|
|
837 |
{
|
|
|
838 |
mailBody += "Detail : " + mReporting.errMsgDetail + "<br>";
|
|
|
839 |
}
|
|
|
840 |
}
|
|
|
841 |
|
|
|
842 |
mailBody += "RM Link : " + CreateUrls.generateRmUrl(mRtagId,mReporting.packageVersionId) + "<br>" +
|
|
|
843 |
"PVID : " + mReporting.packageVersionId + "<br>" +
|
|
|
844 |
"VcsTag : " + mReporting.newVcsTag + "<br>" +
|
|
|
845 |
"Ripple : " + (mReporting.isRipple ? "Yes" : "No") + "<br>" +
|
|
|
846 |
"Dependencies : " + indent + depends + "<br>" +
|
|
|
847 |
"Build Standards : " + indent + buildStandards;
|
|
|
848 |
|
|
|
849 |
mailBody += "<p><hr>";
|
|
|
850 |
try
|
|
|
851 |
{
|
|
|
852 |
Smtpsend.send( rippleEngine.getMailServer(), // mailServer
|
|
|
853 |
rippleEngine.getMailSender(), // source
|
|
|
854 |
emailTo, // target - send to package owners, or myself
|
|
|
855 |
rippleEngine.getMailSender(), // cc
|
|
|
856 |
null, // bcc
|
|
|
857 |
subject, // subject
|
|
|
858 |
mailBody, // body
|
|
|
859 |
null // attachment
|
|
|
860 |
);
|
|
|
861 |
}
|
|
|
862 |
catch( Exception e )
|
|
|
863 |
{
|
|
|
864 |
mLogger.warn("Email Failure: emailPostBuild:" + e.getMessage());
|
|
|
865 |
}
|
|
|
866 |
mLogger.debug("emailPostBuild. Returning");
|
|
|
867 |
}
|
|
|
868 |
|
|
|
869 |
/**returns 'M'
|
|
|
870 |
*/
|
|
|
871 |
protected char getMode()
|
|
|
872 |
{
|
|
|
873 |
mLogger.debug("getMode");
|
|
|
874 |
return 'M';
|
|
|
875 |
}
|
|
|
876 |
|
|
|
877 |
|
|
|
878 |
}
|