Remove dead-end attempt at real-time smoke tests
This commit is contained in:
parent
a91a52548e
commit
2ec535e865
5 changed files with 0 additions and 229 deletions
|
@ -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<String> listOfSmokeTestClasses = new ArrayList<String>();
|
||||
|
||||
private static final Log log = LogFactory.getLog(SmokeTestController.class.getName());
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq){
|
||||
|
||||
List<TestResult> results = new ArrayList<TestResult>();
|
||||
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<String, Object> body = new HashMap<String, Object>();
|
||||
body.put("results", results);
|
||||
|
||||
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
||||
}
|
||||
|
||||
private void readSmokeTestFilesFromPath(ServletContext context) {
|
||||
|
||||
log.debug("Reading smoketest files from "+ FILE_PATH );
|
||||
Set<String> 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<String> getContentsFromFileStream(InputStream fileStream) {
|
||||
|
||||
List<String> classesList = new ArrayList<String>();
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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??>
|
||||
<h2>${x.result}</h2>
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
Loading…
Add table
Reference in a new issue