Merge from 1.5 branch: NIHVIVO-3973 If the Solr index is not available, do not offer the user the ability to re-index. Show an error message instead.

This commit is contained in:
j2blake 2012-09-26 16:02:27 +00:00
parent eb1d4b9631
commit 9cdffd0c09
2 changed files with 36 additions and 6 deletions

View file

@ -15,6 +15,8 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
@ -26,6 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Red
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup;
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread.WorkLevel; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread.WorkLevel;
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread.WorkLevelStamp; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread.WorkLevelStamp;
@ -151,9 +154,20 @@ public class IndexController extends FreemarkerHttpServlet {
body.put("elapsed", formatElapsedTime(since, new Date())); body.put("elapsed", formatElapsedTime(since, new Date()));
body.put("expected", formatElapsedTime(since, expectedCompletion)); body.put("expected", formatElapsedTime(since, expectedCompletion));
body.put("hasPreviousBuild", since.getTime() > 0L); body.put("hasPreviousBuild", since.getTime() > 0L);
body.put("indexIsConnected", testIndexConnection());
return new TemplateResponseValues(TEMPLATE_NAME, body); return new TemplateResponseValues(TEMPLATE_NAME, body);
} }
private Boolean testIndexConnection() {
try {
SolrSetup.getSolrServer(getServletContext()).ping();
return Boolean.TRUE;
} catch (Exception e) {
log.error("Can't connect to the Solr server.", e);
return Boolean.FALSE;
}
}
private Date figureExpectedCompletion(Date startTime, long totalToDo, private Date figureExpectedCompletion(Date startTime, long totalToDo,
long completedCount) { long completedCount) {
Date now = new Date(); Date now = new Date();
@ -183,11 +197,11 @@ public class IndexController extends FreemarkerHttpServlet {
private String figureCurrentTask(Collection<String> flags) { private String figureCurrentTask(Collection<String> flags) {
if (flags.contains(IndexBuilder.FLAG_REBUILDING)) { if (flags.contains(IndexBuilder.FLAG_REBUILDING)) {
return "rebuilt"; return "Rebuilding";
} else if (flags.contains(IndexBuilder.FLAG_UPDATING)) { } else if (flags.contains(IndexBuilder.FLAG_UPDATING)) {
return "updated"; return "Updating";
} else { } else {
return ""; return "Not working on";
} }
} }

View file

@ -6,9 +6,20 @@
<h2>Search Index Status</h2> <h2>Search Index Status</h2>
<#if worklevel == "IDLE"> <#if !indexIsConnected>
<!-- Can't contact the Solr server. Indexing would be impossible. Show an error message. -->
<section id="error-alert" role="alert">
<img src="${urls.images}/iconAlert.png" width="24" height="24" alert="Error alert icon" />
<p>The search index is not connected.</p>
<p><tt>SolrServer.ping()</tt> failed.
<p>Check startup status page and/or Tomcat logs for more information.</p>
</section>
<#elseif worklevel == "IDLE">
<!-- Solr indexer is idle. Show the button that rebuilds the index. -->
<h3>The search indexer is idle.</h3>
<#if hasPreviousBuild??> <#if hasPreviousBuild??>
<p>Most recent update was at ${since?string("hh:mm:ss a, MMMM dd, yyyy")}</p> <p>The most recent update was at ${since?string("hh:mm:ss a, MMMM dd, yyyy")}</p>
</#if> </#if>
<form action="${actionUrl}" method="POST"> <form action="${actionUrl}" method="POST">
@ -17,11 +28,16 @@
Reset the search index and re-populate it. Reset the search index and re-populate it.
</p> </p>
</form> </form>
<#elseif totalToDo == 0> <#elseif totalToDo == 0>
<!-- Solr indexer is preparing the list of records. Show elapsed time since request. -->
<h3>Preparing to rebuild the search index. </h3> <h3>Preparing to rebuild the search index. </h3>
<p>since ${since?string("hh:mm:ss a, MMMM dd, yyyy")}, elapsed time ${elapsed}</p> <p>since ${since?string("hh:mm:ss a, MMMM dd, yyyy")}, elapsed time ${elapsed}</p>
<#else> <#else>
<h3>The search index is currently being ${currentTask}.</h3> <!-- Solr indexer is re-building the index. Show the progress. -->
<h3>${currentTask} the search index.</h3>
<p>since ${since?string("hh:mm:ss a, MMMM dd, yyyy")}, elapsed time ${elapsed}, estimated total time ${expected}</p> <p>since ${since?string("hh:mm:ss a, MMMM dd, yyyy")}, elapsed time ${elapsed}, estimated total time ${expected}</p>
<p>Completed ${completedCount} out of ${totalToDo} index records.</p> <p>Completed ${completedCount} out of ${totalToDo} index records.</p>
</#if> </#if>