|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.griphyn.common.catalog.work.Database
public class Database
This class implements a work catalog on top of a simple table in a JDBC database. This enables a variety of replica catalog implementations in a transactionally safe, concurrent environment. The table must be defined using the statements appropriate for your database - they are part of the setup in $PEGASUS_HOME/sql/create-my-wf.sql for MYSQL database and in $PEGASUS_HOME/sql/create-pg-wf.sql. If you chose to use an unsupported database, please check, if your database either supports sequence number, or if it supports auto increment columns. If your database supports sequences (e.g. PostGreSQL), you can use a setup similar to the following (for Oracle, the autoinc can be implemented via a trigger).
CREATE TABLE wf_work (
id BIGSERIAL PRIMARY KEY,
basedir TEXT,
vogroup VARCHAR(255),
workflow VARCHAR(255),
run VARCHAR(255),
creator VARCHAR(32),
ctime TIMESTAMP WITH TIME ZONE NOT NULL,
state INTEGER NOT NULL,
mtime TIMESTAMP WITH TIME ZONE NOT NULL,
CONSTRAINT sk_wf_work UNIQUE(basedir,vogroup,workflow,run)
);
CREATE TABLE wf_jobstate (
wfid BIGINT REFERENCES wf_work(id) ON DELETE CASCADE,
jobid VARCHAR(64),
state VARCHAR(24) NOT NULL,
mtime TIMESTAMP WITH TIME ZONE NOT NULL,
site VARCHAR(64),
CONSTRAINT pk_wf_jobstate PRIMARY KEY (wfid,jobid)
);
CREATE INDEX ix_wf_jobstate ON wf_jobstate(jobid);
CREATE TABLE wf_siteinfo (
id BIGSERIAL PRIMARY KEY,
handle VARCHAR(48) NOT NULL,
mtime TIMESTAMP WITH TIME ZONE,
-- gauges
other INTEGER DEFAULT 0,
pending INTEGER DEFAULT 0,
running INTEGER DEFAULT 0,
-- counters
success INTEGER DEFAULT 0,
smtime TIMESTAMP WITH TIME ZONE,
failure INTEGER DEFAULT 0,
fmtime TIMESTAMP WITH TIME ZONE,
CONSTRAINT sk_wf_siteinfo UNIQUE(handle)
);
In case of databases that do not support sequences (e.g. MySQL), do
not specify the create sequence, and use an
auto-increment column for the primary key instead, e.g.:
CREATE TABLE wf_work (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
basedir TEXT,
vogroup VARCHAR(255),
workflow VARCHAR(255),
run VARCHAR(255),
creator VARCHAR(32),
ctime DATETIME NOT NULL,
state INTEGER NOT NULL,
mtime DATETIME NOT NULL,
CONSTRAINT sk_wf_work UNIQUE(basedir(255),vogroup,workflow,run)
) type=InnoDB;
CREATE TABLE wf_jobstate (
wfid BIGINT REFERENCES wf_work(id) ON DELETE CASCADE,
jobid VARCHAR(64),
state VARCHAR(24) NOT NULL,
mtime DATETIME NOT NULL,
site VARCHAR(64),
CONSTRAINT pk_wf_jobstate PRIMARY KEY (wfid,jobid)
) type=InnoDB;
CREATE INDEX ix_wf_jobstate ON wf_jobstate(jobid);
CREATE TABLE wf_siteinfo (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
handle VARCHAR(48) NOT NULL,
mtime DATETIME,
-- gauges
other INTEGER DEFAULT 0,
pending INTEGER DEFAULT 0,
running INTEGER DEFAULT 0,
-- counters
success INTEGER DEFAULT 0,
smtime DATETIME,
failure INTEGER DEFAULT 0,
fmtime DATETIME,
CONSTRAINT sk_wf_siteinfo UNIQUE(handle)
) type=InnoDB;
The site attribute should be specified whenever possible. For the
shell planner, it will always be of value "local".
| Field Summary | |
|---|---|
private boolean |
m_autoinc
Remembers if obtaining generated keys will work or not. |
protected Connection |
mConnection
Maintains the connection to the database over the lifetime of this instance. |
private static String |
mConnectionError
This message is sent whenever one of the member function is executed which relies on an established database context. |
private static String[] |
mCStatements
The statement to prepare to slurp attributes. |
protected LogManager |
mLogger
The handle to the logging object. |
protected PreparedStatement[] |
mStatements
Maintains an essential set of prepared statement, ready to use. |
| Fields inherited from interface org.griphyn.common.catalog.WorkCatalog |
|---|
c_prefix, DB_PREFIX, VERSION |
| Fields inherited from interface org.griphyn.common.catalog.Catalog |
|---|
DB_ALL_PREFIX |
| Constructor Summary | |
|---|---|
Database()
Default empty constructor creates an object that is not yet connected to any database. |
|
Database(String jdbc,
String url,
String username,
String password)
Convenience c'tor: Establishes the connection to the work catalog database. |
|
| Method Summary | |
|---|---|
void |
close()
Explicitely free resources before the garbage collection hits. |
boolean |
connect(Properties props)
Establishes a connection to the database from the properties. |
void |
connect(String url,
String username,
String password)
Connects to the database. |
int |
delete(String basedir,
String vogroup,
String label,
String run)
Deletes a mapping from the work catalog. |
protected PreparedStatement |
getStatement(int i)
Singleton manager for prepared statements. |
int |
insert(String basedir,
String vogroup,
String label,
String run,
String creator,
Date cTime,
Date mTime,
int state)
Inserts a new mapping into the work catalog. |
boolean |
isClosed()
Predicate to check, if the connection with the catalog's implementation is still active. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final String mConnectionError
protected Connection mConnection
protected PreparedStatement[] mStatements
protected LogManager mLogger
private static final String[] mCStatements
private boolean m_autoinc
| Constructor Detail |
|---|
public Database(String jdbc,
String url,
String username,
String password)
throws LinkageError,
ExceptionInInitializerError,
ClassNotFoundException,
SQLException
org.postgresql.Driver com.mysql.jdbc.Driver com.microsoft.jdbc.sqlserver.SQLServerDriver SQLite.JDBCDriver sun.jdbc.odbc.JdbcOdbcDriver
jdbc - is a string containing the full name of the java class
that must be dynamically loaded. This is usually an external jar
file which contains the Java database driver.url - is the database driving URL. This string is database
specific, and tell the JDBC driver, at which host and port the
database listens, permits additional arguments, and selects the
database inside the rDBMS to connect to. Please refer to your
JDBC driver documentation for the format and permitted values.username - is the database user account name to connect with.password - is the database account password to use.
LinkageError - if linking the dynamically loaded driver fails.
This is a run-time error, and does not need to be caught.
ExceptionInInitializerError - if the initialization function
of the driver's instantiation threw an exception itself. This is a
run-time error, and does not need to be caught.
ClassNotFoundException - if the class in your jdbc parameter
cannot be found in your given CLASSPATH environment. Callers must
catch this exception.
SQLException - if something goes awry with the database.
Callers must catch this exception.public Database()
connect( String, String, String )| Method Detail |
|---|
public void connect(String url,
String username,
String password)
throws SQLException
Class.forName( String ) yourself
to load the database JDBC driver jar!
url - is the database driving URL. This string is database
specific, and tell the JDBC driver, at which host and port the
database listens, permits additional arguments, and selects the
database inside the rDBMS to connect to. Please refer to your
JDBC driver documentation for the format and permitted values.username - is the database user account name to connect with.password - is the database account password to use.
SQLException - if something goes awry with the database.
Callers must catch this exception.#JDBCRC( String, String, String, String ),
DriverManager.getConnection( String, String, String )public boolean connect(Properties props)
connect in interface Catalogprops - is the property table with sufficient settings to
establish a link with the database. The minimum key required key is
"url", and possibly "driver". Any other keys depend on the database
driver.
Error - subclasses for runtime errors in the class loader.DriverManager.getConnection( String, Properties )public void close()
close in interface Catalogpublic boolean isClosed()
close().
isClosed in interface Catalogclose()
protected PreparedStatement getStatement(int i)
throws SQLException
i - is the index which prepared statement to check.
SQLException - in case of unable to delete entry.
public int insert(String basedir,
String vogroup,
String label,
String run,
String creator,
Date cTime,
Date mTime,
int state)
throws WorkCatalogException
insert in interface WorkCatalogbasedir - the base directoryvogroup - the vo to which the user belongs to.label - the label in the DAXrun - the run number.creator - the user who is running.cTime - the creation time of the DAXmTime - the modification time.state - the state of the workflow
WorkCatalogException - in case of unable to delete entry.
public int delete(String basedir,
String vogroup,
String label,
String run)
throws WorkCatalogException
delete in interface WorkCatalogbasedir - the base directoryvogroup - the vo to which the user belongs to.label - the label in the DAXrun - the run number.
WorkCatalogException - in case of unable to delete entry.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||