jobPS.setString(3, historyEvent.getUserName());
jobPS.setString(4, historyEvent.getJobConfPath());
jobPS.setString(5, historyEvent.getJobQueueName());
jobPS.setLong(6, historyEvent.getSubmitTime());
WorkflowContext workflowContext = buildWorkflowContext(historyEvent);
// Get workflow information
boolean insertWorkflow = false;
String existingContextString = null;
ResultSet rs = null;
try {
workflowSelectPS.setString(1, workflowContext.getWorkflowId());
workflowSelectPS.execute();
rs = workflowSelectPS.getResultSet();
if (rs.next()) {
existingContextString = rs.getString(1);
} else {
insertWorkflow = true;
}
} catch (SQLException sqle) {
LOG.warn("workflow select failed with: ", sqle);
insertWorkflow = false;
} finally {
try {
if (rs != null)
rs.close();
} catch (SQLException e) {
LOG.error("Exception while closing ResultSet", e);
}
}
// Insert workflow
if (insertWorkflow) {
workflowPS.setString(1, workflowContext.getWorkflowId());
workflowPS.setString(2, workflowContext.getWorkflowName());
workflowPS.setString(3, getWorkflowString(getSanitizedWorkflow(workflowContext, null)));
workflowPS.setString(4, historyEvent.getUserName());
workflowPS.setLong(5, historyEvent.getSubmitTime());
workflowPS.setLong(6, historyEvent.getSubmitTime());
workflowPS.setLong(7, workflowContext.getWorkflowDag().size());
workflowPS.executeUpdate();
LOG.debug("Successfully inserted workflowId = " +
workflowContext.getWorkflowId());
} else {
ObjectMapper om = new ObjectMapper();
WorkflowContext existingWorkflowContext = null;
try {
if (existingContextString != null)
existingWorkflowContext = om.readValue(existingContextString.getBytes(), WorkflowContext.class);
} catch (IOException e) {
LOG.warn("Couldn't read existing workflow context for " + workflowContext.getWorkflowId(), e);
}
WorkflowContext sanitizedWC = getSanitizedWorkflow(workflowContext, existingWorkflowContext);
workflowUpdateTimePS.setString(1, getWorkflowString(sanitizedWC));
workflowUpdateTimePS.setLong(2, sanitizedWC.getWorkflowDag().size());
workflowUpdateTimePS.setLong(3, historyEvent.getSubmitTime());
workflowUpdateTimePS.setLong(4, historyEvent.getSubmitTime());
workflowUpdateTimePS.setString(5, workflowContext.getWorkflowId());
workflowUpdateTimePS.executeUpdate();
LOG.debug("Successfully updated workflowId = " +