time_online = new TimeHandler(this.request, this.timezone);
start = time_online.getStartTime();
end = time_online.getEndTime();
}
DatabaseWriter dbw = new DatabaseWriter(this.cluster);
// setup query
String query;
if (this.query_state != null && this.query_state.equals("read")) {
query = "select block_id,start_time,finish_time,start_time_millis,finish_time_millis,status,state_name,hostname,other_host,bytes from ["+table+"] where finish_time between '[start]' and '[end]' and (state_name like 'read_local' or state_name like 'read_remote')";
} else if (this.query_state != null && this.query_state.equals("write")) {
query = "select block_id,start_time,finish_time,start_time_millis,finish_time_millis,status,state_name,hostname,other_host,bytes from ["+table+"] where finish_time between '[start]' and '[end]' and (state_name like 'write_local' or state_name like 'write_remote' or state_name like 'write_replicated')";
} else {
query = "select block_id,start_time,finish_time,start_time_millis,finish_time_millis,status,state_name,hostname,other_host,bytes from ["+table+"] where finish_time between '[start]' and '[end]' and state_name like '" + query_state + "'";
}
Macro mp = new Macro(start,end,query);
query = mp.toString() + " order by start_time";
ArrayList<HashMap<String, Object>> events = new ArrayList<HashMap<String, Object>>();
ResultSet rs = null;
log.debug("Query: " + query);
// run query, extract results
try {
rs = dbw.query(query);
ResultSetMetaData rmeta = rs.getMetaData();
int col = rmeta.getColumnCount();
while (rs.next()) {
HashMap<String, Object> event = new HashMap<String, Object>();
for(int i=1;i<=col;i++) {
if(rmeta.getColumnType(i)==java.sql.Types.TIMESTAMP) {
event.put(rmeta.getColumnName(i),rs.getTimestamp(i).getTime());
} else {
event.put(rmeta.getColumnName(i),rs.getString(i));
}
}
events.add(event);
}
} catch (SQLException ex) {
// handle any errors
log.error("SQLException: " + ex.getMessage());
log.error("SQLState: " + ex.getSQLState());
log.error("VendorError: " + ex.getErrorCode());
} finally {
dbw.close();
}
log.info(events.size() + " results returned.");
HashSet<String> host_set = new HashSet<String>();