NIHVIVO-336 An initial implementation of Smoke test runner. Checking in basic code that prints the status of Solr Server onto the webpage.
This commit is contained in:
parent
b97cbb60e3
commit
7664bf5093
5 changed files with 137 additions and 0 deletions
|
@ -0,0 +1,43 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
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.utils.smoketest.SolrContextChecker;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.smoketest.TestResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The controller responsible for checking statuses of various
|
||||||
|
* services across the web application. (Ex: Solr Server, etc.)
|
||||||
|
* TODO: This is just an initial test implementation and will continue
|
||||||
|
* to change.
|
||||||
|
*/
|
||||||
|
public class SmokeTestController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final Log log = LogFactory.getLog(SmokeTestController.class.getName());
|
||||||
|
|
||||||
|
private static final String TEMPLATE_NAME = "smokeTest.ftl";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq){
|
||||||
|
|
||||||
|
SolrContextChecker solrContextChecker = new SolrContextChecker();
|
||||||
|
TestResult result = solrContextChecker.test(vreq);
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
body.put("SolrContextChecker", result);
|
||||||
|
|
||||||
|
|
||||||
|
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.smoketest;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Any class that wishes to output status to smoketest.ftl
|
||||||
|
* implements this interface.
|
||||||
|
*/
|
||||||
|
public interface SmokeTestsRunner {
|
||||||
|
|
||||||
|
public TestResult test(VitroRequest vreq);
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.smoketest;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.apache.solr.client.solrj.SolrServer;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A sample class implementing SmokeTestsRunner interface that
|
||||||
|
* prints out to a webpage the status of SolrServer i.e whether it
|
||||||
|
* is up and running or not.
|
||||||
|
* TODO: This is just an initial test implementation and will continue
|
||||||
|
* to change.
|
||||||
|
*/
|
||||||
|
public class SolrContextChecker implements SmokeTestsRunner {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TestResult test(VitroRequest vreq) {
|
||||||
|
|
||||||
|
HttpSession session = vreq.getSession();
|
||||||
|
ServletContext context = (ServletContext)session.getServletContext();
|
||||||
|
|
||||||
|
//get the index details about SolrServer from the context
|
||||||
|
SolrServer server = (SolrServer) context.getAttribute("vitro.local.solr.server");
|
||||||
|
|
||||||
|
TestResult testResult;
|
||||||
|
|
||||||
|
if(server != null){
|
||||||
|
testResult = new TestResult("Solr Server is up and running!", true);
|
||||||
|
}else{
|
||||||
|
testResult = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return testResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.smoketest;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A Basic object that contains the status of a service
|
||||||
|
* and a boolean indicating whether the service is on or off.
|
||||||
|
* TODO: This is an initial implementation and might change significantly
|
||||||
|
* over the course of time. (see NIHVIVO-336)
|
||||||
|
*/
|
||||||
|
public class TestResult {
|
||||||
|
|
||||||
|
private String result = "";
|
||||||
|
private boolean message = false;
|
||||||
|
|
||||||
|
public TestResult(String result, boolean message) {
|
||||||
|
this.result = result;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResult(){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getMessage(){
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
9
webapp/web/templates/freemarker/body/smokeTest.ftl
Normal file
9
webapp/web/templates/freemarker/body/smokeTest.ftl
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||||
|
|
||||||
|
<#-- Template for the body of the SmokeTest page -->
|
||||||
|
<#-- TODO: This is an initial implementation and will continue to evolve. -->
|
||||||
|
|
||||||
|
|
||||||
|
<#if SolrContextChecker??>
|
||||||
|
<h2>${SolrContextChecker.result}</h2>
|
||||||
|
</#if>
|
Loading…
Add table
Reference in a new issue