aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Varghese2014-05-30 18:49:07 (EDT)
committerRoy Varghese2014-05-30 18:49:07 (EDT)
commit991fd8b76797ba664d7c495cd5f8fa2cda9801b8 (patch)
tree309ceac3b96e42f8b911479b9978f1d336279c56
parent775b0c4e045f809ca528acefdb224c3a56f43b7f (diff)
downloadorg.eclipse.hudson.core-991fd8b76797ba664d7c495cd5f8fa2cda9801b8.zip
org.eclipse.hudson.core-991fd8b76797ba664d7c495cd5f8fa2cda9801b8.tar.gz
org.eclipse.hudson.core-991fd8b76797ba664d7c495cd5f8fa2cda9801b8.tar.bz2
Add a placeholder for top level items that cannot be read/loaded.refs/changes/30/27630/1
If for some reason a job config.xml gets deleted or corrupted while Hudson is still running, it can prevent all the jobs from displaying making hudson unusable. This fix returns a placeholder that displays the name and the cause of the error in a tooltip, so that an admin can shut down Hudson safely and fix the error at an appropriate time. Signed-off-by: Roy Varghese <rovarghe@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/Functions.java7
-rw-r--r--hudson-core/src/main/java/hudson/model/BrokenTopLevelItem.java82
-rw-r--r--hudson-core/src/main/java/hudson/model/LazyTopLevelItem.java17
-rw-r--r--hudson-core/src/main/java/hudson/model/TopLevelItemsCache.java14
-rw-r--r--hudson-core/src/main/resources/hudson/views/JobColumn/column.jelly8
5 files changed, 123 insertions, 5 deletions
diff --git a/hudson-core/src/main/java/hudson/Functions.java b/hudson-core/src/main/java/hudson/Functions.java
index 249179d..e6c9f9b 100644
--- a/hudson-core/src/main/java/hudson/Functions.java
+++ b/hudson-core/src/main/java/hudson/Functions.java
@@ -1530,4 +1530,11 @@ public class Functions {
}
return null;
}
+
+ public static boolean isBrokenItem(Item item) {
+ if ( item instanceof hudson.model.BrokenTopLevelItem) {
+ return true;
+ }
+ return false;
+ }
}
diff --git a/hudson-core/src/main/java/hudson/model/BrokenTopLevelItem.java b/hudson-core/src/main/java/hudson/model/BrokenTopLevelItem.java
new file mode 100644
index 0000000..690490d
--- /dev/null
+++ b/hudson-core/src/main/java/hudson/model/BrokenTopLevelItem.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ *
+ * Copyright (c) 2004-2014 Oracle Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Roy Varghese
+ */
+
+package hudson.model;
+
+import java.util.SortedMap;
+
+/**
+ * A placeholder for TopLevelItems that could not be loaded for whatever
+ * reason.
+ *
+ * @author rovarghe@gmail.com
+ */
+public class BrokenTopLevelItem extends Job implements TopLevelItem {
+
+ final private RunMap runMap;
+ final private Exception exception;
+ final private LazyTopLevelItem.Key key;
+
+ BrokenTopLevelItem(LazyTopLevelItem.Key key,
+ Exception exception) {
+ super(key.parent, key.name + " [In Error]");
+
+ this.key = key;
+ this.exception = exception;
+ this.runMap = new RunMap(this);
+ }
+
+ @Override
+ public String getDescription() {
+ return "An error occurred while loading this item:" + exception.getMessage();
+ }
+
+ @Override
+ public boolean isBuildable() {
+ return false;
+ }
+
+ @Override
+ public BuildHistory getBuildHistoryData() {
+ return runMap;
+ }
+
+ @Override
+ protected void removeRun(Run run) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public TopLevelItemDescriptor getDescriptor() {
+ return new TopLevelItemDescriptor() {
+
+ @Override
+ public String getDisplayName() {
+ return key.name + " (Broken/Disabled)";
+ }
+
+ @Override
+ public TopLevelItem newInstance(ItemGroup parent, String name) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ };
+ }
+
+ @Override
+ protected SortedMap _getRuns() {
+ return runMap;
+ }
+
+
+}
diff --git a/hudson-core/src/main/java/hudson/model/LazyTopLevelItem.java b/hudson-core/src/main/java/hudson/model/LazyTopLevelItem.java
index e83a25c..b81a4a5 100644
--- a/hudson-core/src/main/java/hudson/model/LazyTopLevelItem.java
+++ b/hudson-core/src/main/java/hudson/model/LazyTopLevelItem.java
@@ -48,6 +48,9 @@ final class LazyTopLevelItem implements TopLevelItem, IJob, StaplerProxy {
final XmlFile configFile;
final ItemGroup parent;
final String name;
+
+ private boolean loadError = false;
+
Key(XmlFile configFile, ItemGroup parent, String name) {
this.configFile = configFile;
this.parent = parent;
@@ -71,6 +74,13 @@ final class LazyTopLevelItem implements TopLevelItem, IJob, StaplerProxy {
public int hashCode() {
return name.hashCode();
}
+
+ public void setLoadErrorFlag() {
+ loadError = true;
+ }
+ public void clearLoadErrorFlag() {
+ loadError = false;
+ }
}
private final Key key;
@@ -170,7 +180,12 @@ final class LazyTopLevelItem implements TopLevelItem, IJob, StaplerProxy {
@Override
public String getName() {
- return key.name;
+ if ( key.loadError ) {
+ return key.name +"[In Error]";
+ }
+ else {
+ return key.name;
+ }
}
@Override
diff --git a/hudson-core/src/main/java/hudson/model/TopLevelItemsCache.java b/hudson-core/src/main/java/hudson/model/TopLevelItemsCache.java
index aaa1b09..6528510 100644
--- a/hudson-core/src/main/java/hudson/model/TopLevelItemsCache.java
+++ b/hudson-core/src/main/java/hudson/model/TopLevelItemsCache.java
@@ -15,6 +15,7 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@@ -78,9 +79,16 @@ class TopLevelItemsCache {
@Override
public TopLevelItem load(LazyTopLevelItem.Key key) throws Exception {
- TopLevelItem item = (TopLevelItem) key.configFile.read();
- item.onLoad(key.parent, key.name);
- return item;
+ try {
+ TopLevelItem item = (TopLevelItem) key.configFile.read();
+ item.onLoad(key.parent, key.name);
+ key.clearLoadErrorFlag();
+ return item;
+ }
+ catch (IOException ex) {
+ key.setLoadErrorFlag();
+ return new BrokenTopLevelItem(key, ex);
+ }
}
});
diff --git a/hudson-core/src/main/resources/hudson/views/JobColumn/column.jelly b/hudson-core/src/main/resources/hudson/views/JobColumn/column.jelly
index 73b6733..92ac024 100644
--- a/hudson-core/src/main/resources/hudson/views/JobColumn/column.jelly
+++ b/hudson-core/src/main/resources/hudson/views/JobColumn/column.jelly
@@ -21,7 +21,13 @@
style="${indenter.getCss(job)}"
onmouseover="this.className='jobDescription hover';return true;"
onmouseout="this.className='jobDescription';return true;">
- <a href="${jobBaseUrl}${job.shortUrl}">${job.displayName}</a>
+ <j:if test="${h.isBrokenItem(job)}">
+ <a class="redbold" href="#${job.displayName}">${job.displayName}</a>
+ </j:if>
+
+ <j:if test="${!h.isBrokenItem(job)}">
+ <a href="${jobBaseUrl}${job.shortUrl}">${job.displayName}</a>
+ </j:if>
<j:if test="${!empty(job.description)}">
<div class="jobDescriptionDetails">
<table border="0">