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 deleted file mode 100644 index c6c05cf33..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SmokeTestController.java +++ /dev/null @@ -1,124 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.controller.freemarker; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.List; -import java.util.ArrayList; - -import javax.servlet.ServletContext; - -import org.apache.commons.lang.StringUtils; -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.SmokeTest; -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 String TEMPLATE_NAME = "smokeTest.ftl"; - private static final String FILE_PATH = "/WEB-INF/classes/smokeTests"; - private static final String PACKAGE_CONTAINING_SMOKETEST_CLASSES = "edu.cornell.mannlib.vitro.webapp.utils.smoketest."; - - private List listOfSmokeTestClasses = new ArrayList(); - - private static final Log log = LogFactory.getLog(SmokeTestController.class.getName()); - - @Override - protected ResponseValues processRequest(VitroRequest vreq){ - - List results = new ArrayList(); - ServletContext context = vreq.getSession().getServletContext(); - readSmokeTestFilesFromPath(context); - - for(String className : listOfSmokeTestClasses){ - try { - - Class thisClass = Class.forName(PACKAGE_CONTAINING_SMOKETEST_CLASSES +""+ className); - SmokeTest smokeTestsRunner = (SmokeTest)thisClass.newInstance(); - - results.add(smokeTestsRunner.test(vreq)); - - } catch (ClassNotFoundException e) { - log.error("Class not found "+ e); - } catch(IllegalAccessException e){ - log.error("Illegal access of the class " + e); - } catch(InstantiationException e){ - log.error("Error instantiating class " + e); - } - } - - - Map body = new HashMap(); - body.put("results", results); - - return new TemplateResponseValues(TEMPLATE_NAME, body); - } - - private void readSmokeTestFilesFromPath(ServletContext context) { - - log.debug("Reading smoketest files from "+ FILE_PATH ); - Set paths = context.getResourcePaths(FILE_PATH); - if(paths != null){ - for(String p : paths){ - readSmokeTestClassesFromFile(p, context); - } - } - } - - private void readSmokeTestClassesFromFile(String p, ServletContext context) { - //check that this is a file and not a directory. - File f = new File(context.getRealPath(p)); - if(f.exists() && f.isFile()){ - InputStream fileStream = context.getResourceAsStream(p); - listOfSmokeTestClasses.addAll(getContentsFromFileStream(fileStream)); - } else { - if(!f.exists()){ - log.debug("File for path " + p + " does not exist"); - }else if(f.isDirectory()){ - log.debug("Path " + p + " corresponds to a directory and not file. File was not read."); - } - } - } - - private List getContentsFromFileStream(InputStream fileStream) { - - List classesList = new ArrayList(); - BufferedReader reader = new BufferedReader(new InputStreamReader(fileStream)); - String text = ""; - - try { - while((text = reader.readLine()) != null){ - //ignore comments in the file. - if(text.startsWith("#") || StringUtils.isEmpty(text) || StringUtils.isBlank(text)){ - continue; - } - classesList.add(text); - } - } catch (IOException e) { - log.error("Error reading file " + e); - } - return classesList; - - } -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/SmokeTest.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/SmokeTest.java deleted file mode 100644 index c23ba50bc..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/SmokeTest.java +++ /dev/null @@ -1,16 +0,0 @@ -/* $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 SmokeTest { - - public TestResult test(VitroRequest vreq); - - public String getName(); -} 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 deleted file mode 100644 index 2c1fb6662..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/SolrContextChecker.java +++ /dev/null @@ -1,46 +0,0 @@ -/* $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 SmokeTest { - - @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; - } - - @Override - public String getName(){ - return SolrContextChecker.class.getName(); - } - -} 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 deleted file mode 100644 index c91a6279a..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/smoketest/TestResult.java +++ /dev/null @@ -1,30 +0,0 @@ -/* $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 success = false; - - public TestResult(String result, boolean message) { - this.result = result; - this.success = message; - } - - public String getResult(){ - return result; - } - - public boolean getMessage(){ - return success; - } - - -} diff --git a/webapp/web/templates/freemarker/body/smokeTest.ftl b/webapp/web/templates/freemarker/body/smokeTest.ftl deleted file mode 100644 index 6970ff9ad..000000000 --- a/webapp/web/templates/freemarker/body/smokeTest.ftl +++ /dev/null @@ -1,13 +0,0 @@ -<#-- $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 results??> - <#list results as x> - <#if x??> -

${x.result}

- - - \ No newline at end of file