diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SmokeTestController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SmokeTestController.java new file mode 100644 index 000000000..a65ef59e6 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SmokeTestController.java @@ -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 body = new HashMap(); + + body.put("SolrContextChecker", result); + + + return new TemplateResponseValues(TEMPLATE_NAME, body); + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/SmokeTestsRunner.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/SmokeTestsRunner.java new file mode 100644 index 000000000..002e3bfd5 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/SmokeTestsRunner.java @@ -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); +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/SolrContextChecker.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/SolrContextChecker.java new file mode 100644 index 000000000..00e485288 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/SolrContextChecker.java @@ -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; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/TestResult.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/TestResult.java new file mode 100644 index 000000000..5a27c307c --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/TestResult.java @@ -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; + } + + +} diff --git a/webapp/web/templates/freemarker/body/smokeTest.ftl b/webapp/web/templates/freemarker/body/smokeTest.ftl new file mode 100644 index 000000000..4661f86b6 --- /dev/null +++ b/webapp/web/templates/freemarker/body/smokeTest.ftl @@ -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??> +

${SolrContextChecker.result}

+ \ No newline at end of file