Skip to content
Snippets Groups Projects
Commit 0f848933 authored by Robert Butora's avatar Robert Butora
Browse files

availability: adds check on DB connection

parent 81e59d02
No related branches found
No related tags found
No related merge requests found
......@@ -80,6 +80,35 @@ public class DbObstap
}
public int queryObstapRowCount()
throws Exception
{
LOGGER.fine("trace");
String theQuery = "SELECT count(*) AS total FROM obscore";
LOGGER.fine(theQuery);
LOGGER.fine("Connecting to: " + dbConnArgs.uri() + " with user: " + dbConnArgs.userName() );
int rowCount = -1;
try(
Connection conn = DriverManager.getConnection(dbConnArgs.uri(), dbConnArgs.userName(), dbConnArgs.password());
Statement st = conn.createStatement();
ResultSet res = st.executeQuery(theQuery);)
{
while (res.next())
{
rowCount = res.getInt("total");
}
}
catch (SQLException se)
{
dbError(se);
// se.printStackTrace();
throw new Exception(se.toString());
}
return rowCount;
}
public String[] queryOverlapingPubdid(QueryArgs qArgs)
......
......@@ -27,24 +27,47 @@ import static java.nio.file.StandardCopyOption.*;
public class VosiServlet
extends javax.servlet.http.HttpServlet
{
// for logs and debug
String className = this.getClass().getSimpleName();
private static final SearchSettings settings = SearchSettings.getInstance("search.properties");
// VOSI
// String accessURL = null; // FIXME now read from MERGEURL later introduce own param
// String funcName = "vlkb_cutout"; // FIXME read from config file
private static final String availStr =
private String availString()
{
boolean available;
int obstapRowCount = -1;
DbObstap dbObstap;
String note;
try
{
synchronized(DbObstap.class)
{
dbObstap = new DbObstap(settings.dbConnArgs);
}
obstapRowCount = dbObstap.queryObstapRowCount();
available = (obstapRowCount >= 0);
note = "Table obstap in " + settings.dbConnArgs.toString() + " has "
+ String.valueOf(obstapRowCount) + " rows";
}
catch(Exception ex)
{
note = "Accessing " + settings.dbConnArgs.toString()
+ " failed with " + ex.toString();
available = false;
}
String availStr =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<vosi:availability "
+ " xmlns:vosi=\"http://www.ivoa.net/xml/VOSIAvailability/v1.0\">"
+ " <vosi:available>true</vosi:available>"
+ "<vosi:availability xmlns:vosi=\"http://www.ivoa.net/xml/VOSIAvailability/v1.0\">"
+ "<vosi:available> "+ (available ? "true":"false") +" </vosi:available>"
+ "<vosi:note> VLKB-SIAv2 "+ Version.asString +" is accepting queries </vosi:note>"
+ "<vosi:note> " + note + " </vosi:note>"
+ "</vosi:availability>";
private String capsStr = null;
return availStr;
}
private String capsStr = null;
protected void SetCapsStr(String URL, String funcName)
{
if(URL != null)
......@@ -138,7 +161,7 @@ public class VosiServlet
}
else if(-1 != requestURL.lastIndexOf("/availability"))
{
writer.println(availStr);
writer.println(availString());
}
// error FIXME what to do if none of above given ? e.g. misconfigured web.xml
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment