aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Varghese2014-06-05 16:27:47 (EDT)
committerRoy Varghese2014-06-05 16:27:47 (EDT)
commit9ed0d6eca085de54705637069ecf21a7b9958169 (patch)
treef0fa899974e96e1f64bbadb21d3c4de829cf941e
parent2d9a975f7d5422d551fe9c49468fa2f16942ff68 (diff)
downloadorg.eclipse.hudson.core-9ed0d6eca085de54705637069ecf21a7b9958169.zip
org.eclipse.hudson.core-9ed0d6eca085de54705637069ecf21a7b9958169.tar.gz
org.eclipse.hudson.core-9ed0d6eca085de54705637069ecf21a7b9958169.tar.bz2
Prevent a build load failure from losing all build history for a job.refs/changes/78/28078/1
With this change, a placeholder build object will be created if a build.xml file fails to load for whatever reason. This ensure user is able to list some of the cached details of the build (prior to it becoming unloadable) as well as navigate through it to previous and next builds. Signed-off-by: Roy Varghese <rovarghe@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/Run.java27
-rw-r--r--hudson-core/src/main/java/hudson/model/RunMap.java22
2 files changed, 46 insertions, 3 deletions
diff --git a/hudson-core/src/main/java/hudson/model/Run.java b/hudson-core/src/main/java/hudson/model/Run.java
index c51311b..fcb1af4 100644
--- a/hudson-core/src/main/java/hudson/model/Run.java
+++ b/hudson-core/src/main/java/hudson/model/Run.java
@@ -147,7 +147,7 @@ public abstract class Run<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
/**
* When the build is scheduled.
*/
- protected transient final long timestamp;
+ protected transient long timestamp;
/**
* The build result. This value may change while the state is in
* {@link State#BUILDING}.
@@ -267,6 +267,10 @@ public abstract class Run<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Unable to load Run object.", ex);
dataFileLoadException = ex;
+ RunMap.LazyRunValue.Key key = RunMap.LazyRunValue.getCurrentKey();
+ if ( key != null ) {
+ loadCachedValues(key);
+ }
}
}
@@ -359,6 +363,22 @@ public abstract class Run<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
final State getState() {
return state;
}
+
+ final void loadCachedValues(RunMap.LazyRunValue.Key key) {
+ this.number = key.referenced.buildNumber;
+ this.description = String.format("%s\n%s",
+ this.dataFileLoadException.getMessage(),
+ key.referenced.description == null? "":
+ key.referenced.description);
+
+ this.displayName = String.format("%s [In Error]",key.referenced.displayName);
+ this.duration = key.referenced.duration;
+ this.nextBuild = (RunT)key.referenced.getNextBuild();
+ this.previousBuild = (RunT)key.referenced.getPreviousBuild();
+ this.result = key.referenced.result;
+ this.state = key.referenced.state;
+ this.timestamp = key.referenced.timeInMillis;
+ }
/**
* Gets the subset of {@link #getActions()} that consists of
@@ -1585,6 +1605,11 @@ public abstract class Run<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
* Save the settings to a file.
*/
public synchronized void save() throws IOException {
+ // Don't save if load didn't succeed.
+ if (hasLoadFailure()) {
+ return;
+ }
+
if (BulkChange.contains(this)) {
return;
}
diff --git a/hudson-core/src/main/java/hudson/model/RunMap.java b/hudson-core/src/main/java/hudson/model/RunMap.java
index 60b3ac0..eaa6605 100644
--- a/hudson-core/src/main/java/hudson/model/RunMap.java
+++ b/hudson-core/src/main/java/hudson/model/RunMap.java
@@ -773,7 +773,15 @@ public final class RunMap<J extends Job<J, R>, R extends Run<J, R>>
public Run load(LazyRunValue.Key key) throws Exception {
LazyRunValue.Key k = (LazyRunValue.Key)key;
+ // Load the data from storage
+ // This may not succeed, so set the cached values in a
+ // thread context variable for Run to retrieve it. This way
+ // we don't throw, but end up with a placehold build object for
+ // unloadable builds.
+ LazyRunValue.setCurrentKey(k);
Run r = k.ctor.create(k.referenced.buildDir());
+ LazyRunValue.setCurrentKey(null);
+
if ( r instanceof BuildNavigable) {
((BuildNavigable)r).setBuildNavigator(k.referenced);
}
@@ -1504,11 +1512,11 @@ public final class RunMap<J extends Job<J, R>, R extends Run<J, R>>
extends RunValue<J,R> {
- private static class Key {
+ static class Key {
private String buildDir;
private File buildsDir;
private transient RunMap.Constructor ctor;
- private final LazyRunValue referenced;
+ final LazyRunValue referenced;
private volatile boolean refreshed;
Key(File buildsDir, String buildDir, RunMap.Constructor ctor, LazyRunValue ref) {
@@ -1537,6 +1545,8 @@ public final class RunMap<J extends Job<J, R>, R extends Run<J, R>>
private final Key key;
+ static private ThreadLocal<Key> currentKey = new ThreadLocal<Key>();
+
private LazyRunValue(RunMap runMap) {
// Used when loaded from file
this.key = new Key(null, null, null, this);
@@ -1566,6 +1576,14 @@ public final class RunMap<J extends Job<J, R>, R extends Run<J, R>>
}
return v;
}
+
+ static Key getCurrentKey() {
+ return currentKey.get();
+ }
+
+ static void setCurrentKey(Key key) {
+ currentKey.set(key);
+ }