mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +00:00
Record 'isUI' in database; add code to 'dspace version' to consume the table.
This commit is contained in:
@@ -11,7 +11,9 @@ package org.dspace.app.util;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.management.InstanceAlreadyExistsException;
|
||||
import javax.management.InstanceNotFoundException;
|
||||
import javax.management.MBeanRegistration;
|
||||
@@ -23,6 +25,8 @@ import javax.management.ObjectName;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
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.LoggerFactory;
|
||||
|
||||
@@ -38,17 +42,18 @@ abstract public class AbstractDSpaceWebapp
|
||||
{
|
||||
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 AbstractDSpaceWebapp()
|
||||
protected AbstractDSpaceWebapp()
|
||||
{
|
||||
KIND = null;
|
||||
started = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a particular kind of DSpace application.
|
||||
*
|
||||
@@ -56,28 +61,29 @@ abstract public class AbstractDSpaceWebapp
|
||||
*/
|
||||
public AbstractDSpaceWebapp(String kind)
|
||||
{
|
||||
KIND = kind;
|
||||
this.kind = kind;
|
||||
|
||||
started = new Date();
|
||||
|
||||
url = ConfigurationManager.getProperty("dspace.url");
|
||||
if (null == url)
|
||||
{
|
||||
throw new IllegalStateException("dspace.url is undefined");
|
||||
}
|
||||
}
|
||||
|
||||
/** Record that this application is running. */
|
||||
public void register()
|
||||
{
|
||||
String url = ConfigurationManager.getProperty("dspace.url");
|
||||
if (null == url)
|
||||
{
|
||||
throw new IllegalStateException("dspace.url is undefined");
|
||||
}
|
||||
|
||||
// Create the database entry
|
||||
Timestamp now = new Timestamp(new Date().getTime());
|
||||
try {
|
||||
Context context = new Context();
|
||||
DatabaseManager.updateQuery(context,
|
||||
"DELETE FROM Webapp WHERE AppName = ?", KIND);
|
||||
"DELETE FROM Webapp WHERE AppName = ?", kind);
|
||||
DatabaseManager.updateQuery(context,
|
||||
"INSERT INTO Webapp (AppName, URL, Started) VALUES(?, ?, ?);",
|
||||
KIND, url, now);
|
||||
"INSERT INTO Webapp (AppName, URL, Started, isUI) VALUES(?, ?, ?, ?);",
|
||||
kind, url, now, isUI() ? 1 : 0);
|
||||
context.complete();
|
||||
} catch (SQLException e) {
|
||||
log.error("Failed to record startup in Webapp table.", e);
|
||||
@@ -104,7 +110,7 @@ abstract public class AbstractDSpaceWebapp
|
||||
try {
|
||||
Context context = new Context();
|
||||
DatabaseManager.updateQuery(context,
|
||||
"DELETE FROM Webapp WHERE AppName = ?", KIND);
|
||||
"DELETE FROM Webapp WHERE AppName = ?", kind);
|
||||
context.complete();
|
||||
} catch (SQLException 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 */
|
||||
|
||||
@Override
|
||||
public String getKind()
|
||||
{
|
||||
return KIND;
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getURL()
|
||||
{
|
||||
return ConfigurationManager.getProperty("dspace.url");
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,7 +189,7 @@ abstract public class AbstractDSpaceWebapp
|
||||
public ObjectName preRegister(MBeanServer mbs, ObjectName on)
|
||||
throws Exception
|
||||
{
|
||||
return new ObjectName(DSpaceWebappMXBean.class.getName(), "Kind", KIND);
|
||||
return new ObjectName(DSpaceWebappMXBean.class.getName(), "Kind", kind);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -168,4 +207,16 @@ abstract public class AbstractDSpaceWebapp
|
||||
public void postDeregister()
|
||||
{
|
||||
}
|
||||
|
||||
static private class DSpaceWebapp
|
||||
extends AbstractDSpaceWebapp
|
||||
{
|
||||
private boolean uiQ;
|
||||
|
||||
@Override
|
||||
public boolean isUI()
|
||||
{
|
||||
return uiQ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -49,7 +49,14 @@ public class Version
|
||||
sys.get("os.arch"),
|
||||
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?
|
||||
ConfigurationService config = new DSpace().getConfigurationService();
|
||||
@@ -57,11 +64,13 @@ public class Version
|
||||
List<String> consumerList = Arrays.asList(consumers.split("\\s*,\\s*"));
|
||||
if (consumerList.contains("discovery"))
|
||||
{
|
||||
System.out.println("Discovery enabled.");
|
||||
System.out.println(" Discovery: enabled.");
|
||||
}
|
||||
|
||||
// Is Lucene search enabled?
|
||||
if (consumerList.contains("search"))
|
||||
{
|
||||
System.out.println("Lucene search enabled.");
|
||||
System.out.println(" Lucene search: enabled.");
|
||||
}
|
||||
|
||||
// Java version
|
||||
|
@@ -811,5 +811,6 @@ CREATE TABLE Webapp
|
||||
(
|
||||
AppName VARCHAR(32) NOT NULL PRIMARY KEY,
|
||||
URL VARCHAR NOT NULL,
|
||||
Started TIMESTAMP
|
||||
Started TIMESTAMP,
|
||||
isUI INTEGER
|
||||
);
|
||||
|
@@ -756,5 +756,6 @@ CREATE TABLE Webapp
|
||||
(
|
||||
AppName VARCHAR(32) NOT NULL PRIMARY KEY,
|
||||
URL VARCHAR NOT NULL,
|
||||
Started TIMESTAMP
|
||||
Started TIMESTAMP,
|
||||
isUI INTEGER
|
||||
);
|
||||
|
@@ -802,5 +802,6 @@ CREATE TABLE Webapp
|
||||
(
|
||||
AppName VARCHAR(32) NOT NULL PRIMARY KEY,
|
||||
URL VARCHAR NOT NULL,
|
||||
Started TIMESTAMP
|
||||
Started TIMESTAMP,
|
||||
isUI Boolean
|
||||
);
|
||||
|
Reference in New Issue
Block a user