Skip to content
This repository was archived by the owner on Jul 2, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DAQAggregator_example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ session.l0filter2 = PublicGlobal
# settings concerning HWCFG DB
# ask your collegue for credentials
#
hwcfgdb.type = ORACLE
hwcfgdb.host = localhost
hwcfgdb.port = 10121
hwcfgdb.sid =
Expand Down
13 changes: 10 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,16 @@
<artifactId>commons-math3</artifactId>
<version>3.0</version>
</dependency>



<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.21.0</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<distributionManagement>
<repository>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/rcms/utilities/daqaggregator/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public enum Settings {
MONITOR_SETUPNAME("monitor.setupName"),

// settings concerning HWCFG DB
HWCFGDB_TYPE("hwcfgdb.type"),
HWCFGDB_DBURL("hwcfgdb.dburl"),
HWCFGDB_HOST("hwcfgdb.host"),
HWCFGDB_PORT("hwcfgdb.port"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package rcms.utilities.daqaggregator.datasource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.commons.dbcp.DelegatingConnection;
import rcms.common.db.AbstractDBConnector;
import rcms.common.db.DBConnectorException;

/**
* class wrapping around a SQLite connection object to rewrite certain SQL
* queries
*
* @author holzner
*/
class RewritingConnection extends DelegatingConnection {

public RewritingConnection(Connection conn) {
super(conn);
}

// original query to catch
private static final String refQuery1 = "WITH "
+ " ho AS (SELECT * FROM DAQ_EQCFG_HOST WHERE eqset_id = ?), "
+ " ha AS (SELECT * FROM DAQ_EQCFG_HOST_ATTRIBUTE WHERE eqset_id = ?), "
+ " hn AS (SELECT * FROM DAQ_EQCFG_HOST_NIC WHERE eqset_id = ?), "
+ " ni AS (SELECT * FROM DAQ_EQCFG_NIC WHERE eqset_id = ?), "
+ " dn AS (SELECT * FROM DAQ_EQCFG_DNSNAME WHERE eqset_id = ?) "
+ "SELECT ho.host_id, "
+ " ho.ncores, "
+ " ha.attr_name, "
+ " ha.attr_value, "
+ " ni.nic_id, "
+ " ni.device_name, "
+ " dn.dnsname, "
+ " dn.network_name "
+ "FROM ho, ha, hn, ni, dn WHERE "
+ " ho.host_id = hn.host_id AND"
+ " ha.host_id(+) = ho.host_id AND"
+ " hn.nic_id = ni.nic_id AND"
+ " ni.nic_id = dn.nic_id ORDER BY ho.host_id";

// substitution query
private static final String subsQuery1 = "WITH "
+ " ho AS (SELECT * FROM DAQ_EQCFG_HOST WHERE eqset_id = ?), "
+ " ha AS (SELECT * FROM DAQ_EQCFG_HOST_ATTRIBUTE WHERE eqset_id = ?), "
+ " hn AS (SELECT * FROM DAQ_EQCFG_HOST_NIC WHERE eqset_id = ?), "
+ " ni AS (SELECT * FROM DAQ_EQCFG_NIC WHERE eqset_id = ?), "
+ " dn AS (SELECT * FROM DAQ_EQCFG_DNSNAME WHERE eqset_id = ?) "
+ "SELECT ho.host_id, "
+ " ho.ncores, "
+ " ha.attr_name, "
+ " ha.attr_value, "
+ " ni.nic_id, "
+ " ni.device_name, "
+ " dn.dnsname, "
+ " dn.network_name "
+ "FROM ho, ha, hn, ni, dn WHERE "
+ " ho.host_id = hn.host_id AND"
+ // " ha.host_id(+) = ho.host_id AND" +
" ha.host_id = ho.host_id AND"
+ " hn.nic_id = ni.nic_id AND"
+ " ni.nic_id = dn.nic_id ORDER BY ho.host_id";

@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {

// TODO: should ignore/collapse multiple consecutive whitespace
// during comparison for somewhat more robust comparison
if (sql.equals(refQuery1)) {
sql = subsQuery1;
}

return super.prepareStatement(sql);
}
}

/**
* class to access hardware database information in an SQLite database
*/
public class DBConnectorSqlite extends AbstractDBConnector {

DBConnectorSqlite(String url) {
this.url = url;
super.startQueryWatcher();
}

@Override
public void openConnection() throws DBConnectorException {

if (!queryWatcher.isAlive()) {
super.startQueryWatcher();
}

try {
this.connection = new RewritingConnection(DriverManager.getConnection(url));
} catch (SQLException ex) {
throw new DBConnectorException("failed to connect to database " + url, ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ public DAQPartition getPartition(String _dpsetPath)
return dpset.getDPs().values().iterator().next();
}

public void initialize(String url, String host, String port, String sid, String user, String passwd)
public void initialize(String dbType, String url, String host, String port, String sid, String user, String passwd)
throws DBConnectorException, HardwareConfigurationException {
String _dbType = "ORACLE";

if (url == null || url.isEmpty()) {
url = "jdbc:oracle:thin:@" + host + ":" + port + "/" + sid;
}

if (_dbType.equals("ORACLE"))
if (dbType.equals("ORACLE"))
_dbconn = new DBConnectorOracle(url, user, passwd);
else if (dbType.equals("SQLITE"))
_dbconn = new DBConnectorSqlite(url);
else
_dbconn = new DBConnectorMySQL(url, user, passwd);

Expand All @@ -44,13 +46,19 @@ public void initialize(String url, String host, String port, String sid, String
public void initialize(Properties prop) throws DBConnectorException,
HardwareConfigurationException {

String type = prop.getProperty(Settings.HWCFGDB_TYPE.getKey());
String url = prop.getProperty(Settings.HWCFGDB_DBURL.getKey());
String host = prop.getProperty(Settings.HWCFGDB_HOST.getKey());
String port = prop.getProperty(Settings.HWCFGDB_PORT.getKey());
String sid = prop.getProperty(Settings.HWCFGDB_SID.getKey());
String user = prop.getProperty(Settings.HWCFGDB_LOGIN.getKey());
String passwd = prop.getProperty(Settings.HWCFGDB_PWD.getKey());

initialize(url, host, port, sid, user, passwd);
initialize(type, url, host, port, sid, user, passwd);
}

static DBConnectorIF getDbconn() {
return _dbconn;
}

}
Loading