Record 'isUI' in database; add code to 'dspace version' to consume the table.

This commit is contained in:
Mark H. Wood
2013-06-14 10:20:44 -04:00
parent e0fb4367f6
commit 9b26731c83
5 changed files with 93 additions and 30 deletions

View File

@@ -11,7 +11,9 @@ package org.dspace.app.util;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import javax.management.InstanceAlreadyExistsException; import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException; import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistration; import javax.management.MBeanRegistration;
@@ -23,6 +25,8 @@ import javax.management.ObjectName;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.storage.rdbms.DatabaseManager; import org.dspace.storage.rdbms.DatabaseManager;
import org.dspace.storage.rdbms.TableRow;
import org.dspace.storage.rdbms.TableRowIterator;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -38,46 +42,48 @@ abstract public class AbstractDSpaceWebapp
{ {
private static final Logger log = LoggerFactory.getLogger(AbstractDSpaceWebapp.class); private static final Logger log = LoggerFactory.getLogger(AbstractDSpaceWebapp.class);
private final String KIND; protected String kind;
protected final Date started; protected Date started;
protected String url;
private ObjectInstance mbeanInstance; private ObjectInstance mbeanInstance;
private AbstractDSpaceWebapp() protected AbstractDSpaceWebapp()
{ {
KIND = null;
started = null;
} }
/**
* Construct a particular kind of DSpace application. /**
* * Construct a particular kind of DSpace application.
* @param kind what kind of application is this? (XMLUI, JSPUI, etc.) *
*/ * @param kind what kind of application is this? (XMLUI, JSPUI, etc.)
*/
public AbstractDSpaceWebapp(String kind) public AbstractDSpaceWebapp(String kind)
{ {
KIND = kind; this.kind = kind;
started = new Date(); started = new Date();
url = ConfigurationManager.getProperty("dspace.url");
if (null == url)
{
throw new IllegalStateException("dspace.url is undefined");
}
} }
/** Record that this application is running. */ /** Record that this application is running. */
public void register() public void register()
{ {
String url = ConfigurationManager.getProperty("dspace.url");
if (null == url)
{
throw new IllegalStateException("dspace.url is undefined");
}
// Create the database entry // Create the database entry
Timestamp now = new Timestamp(new Date().getTime()); Timestamp now = new Timestamp(new Date().getTime());
try { try {
Context context = new Context(); Context context = new Context();
DatabaseManager.updateQuery(context, DatabaseManager.updateQuery(context,
"DELETE FROM Webapp WHERE AppName = ?", KIND); "DELETE FROM Webapp WHERE AppName = ?", kind);
DatabaseManager.updateQuery(context, DatabaseManager.updateQuery(context,
"INSERT INTO Webapp (AppName, URL, Started) VALUES(?, ?, ?);", "INSERT INTO Webapp (AppName, URL, Started, isUI) VALUES(?, ?, ?, ?);",
KIND, url, now); kind, url, now, isUI() ? 1 : 0);
context.complete(); context.complete();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Failed to record startup in Webapp table.", e); log.error("Failed to record startup in Webapp table.", e);
@@ -104,7 +110,7 @@ abstract public class AbstractDSpaceWebapp
try { try {
Context context = new Context(); Context context = new Context();
DatabaseManager.updateQuery(context, DatabaseManager.updateQuery(context,
"DELETE FROM Webapp WHERE AppName = ?", KIND); "DELETE FROM Webapp WHERE AppName = ?", kind);
context.complete(); context.complete();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Failed to record shutdown in Webapp table.", e); log.error("Failed to record shutdown in Webapp table.", e);
@@ -124,18 +130,51 @@ abstract public class AbstractDSpaceWebapp
} }
} }
/** Return the list of running applications. */
static public List<AbstractDSpaceWebapp> getApps()
{
ArrayList<AbstractDSpaceWebapp> apps = new ArrayList<AbstractDSpaceWebapp>();
TableRowIterator tri;
Context context = null;
try {
context = new Context();
tri = DatabaseManager.queryTable(context, "Webapp",
"SELECT AppName, URL, Started, isUI FROM Webapp");
for (TableRow row : tri.toList())
{
DSpaceWebapp app = new DSpaceWebapp();
app.kind = row.getStringColumn("AppName");
app.url = row.getStringColumn("URL");
app.started = row.getDateColumn("Started");
app.uiQ = row.getBooleanColumn("isUI");
apps.add(app);
}
} catch (SQLException e) {
log.error("Unable to list running applications", e);
} finally {
if (null != context)
{
context.abort();
}
}
return apps;
}
/* DSpaceWebappMXBean methods */ /* DSpaceWebappMXBean methods */
@Override @Override
public String getKind() public String getKind()
{ {
return KIND; return kind;
} }
@Override @Override
public String getURL() public String getURL()
{ {
return ConfigurationManager.getProperty("dspace.url"); return url;
} }
@Override @Override
@@ -150,7 +189,7 @@ abstract public class AbstractDSpaceWebapp
public ObjectName preRegister(MBeanServer mbs, ObjectName on) public ObjectName preRegister(MBeanServer mbs, ObjectName on)
throws Exception throws Exception
{ {
return new ObjectName(DSpaceWebappMXBean.class.getName(), "Kind", KIND); return new ObjectName(DSpaceWebappMXBean.class.getName(), "Kind", kind);
} }
@Override @Override
@@ -168,4 +207,16 @@ abstract public class AbstractDSpaceWebapp
public void postDeregister() public void postDeregister()
{ {
} }
static private class DSpaceWebapp
extends AbstractDSpaceWebapp
{
private boolean uiQ;
@Override
public boolean isUI()
{
return uiQ;
}
}
} }

View File

@@ -49,7 +49,14 @@ public class Version
sys.get("os.arch"), sys.get("os.arch"),
sys.get("os.version")); sys.get("os.version"));
// TODO UIs used // UIs used
List<AbstractDSpaceWebapp> apps = AbstractDSpaceWebapp.getApps();
System.out.println(" Applications:");
for (AbstractDSpaceWebapp app : apps)
{
System.out.printf(" %s at %s\n",
app.getKind(), app.getURL());
}
// Is Discovery available? // Is Discovery available?
ConfigurationService config = new DSpace().getConfigurationService(); ConfigurationService config = new DSpace().getConfigurationService();
@@ -57,11 +64,13 @@ public class Version
List<String> consumerList = Arrays.asList(consumers.split("\\s*,\\s*")); List<String> consumerList = Arrays.asList(consumers.split("\\s*,\\s*"));
if (consumerList.contains("discovery")) if (consumerList.contains("discovery"))
{ {
System.out.println("Discovery enabled."); System.out.println(" Discovery: enabled.");
} }
// Is Lucene search enabled?
if (consumerList.contains("search")) if (consumerList.contains("search"))
{ {
System.out.println("Lucene search enabled."); System.out.println(" Lucene search: enabled.");
} }
// Java version // Java version

View File

@@ -811,5 +811,6 @@ CREATE TABLE Webapp
( (
AppName VARCHAR(32) NOT NULL PRIMARY KEY, AppName VARCHAR(32) NOT NULL PRIMARY KEY,
URL VARCHAR NOT NULL, URL VARCHAR NOT NULL,
Started TIMESTAMP Started TIMESTAMP,
isUI INTEGER
); );

View File

@@ -756,5 +756,6 @@ CREATE TABLE Webapp
( (
AppName VARCHAR(32) NOT NULL PRIMARY KEY, AppName VARCHAR(32) NOT NULL PRIMARY KEY,
URL VARCHAR NOT NULL, URL VARCHAR NOT NULL,
Started TIMESTAMP Started TIMESTAMP,
isUI INTEGER
); );

View File

@@ -802,5 +802,6 @@ CREATE TABLE Webapp
( (
AppName VARCHAR(32) NOT NULL PRIMARY KEY, AppName VARCHAR(32) NOT NULL PRIMARY KEY,
URL VARCHAR NOT NULL, URL VARCHAR NOT NULL,
Started TIMESTAMP Started TIMESTAMP,
isUI Boolean
); );