Skip to content
Snippets Groups Projects
Commit ae47c967 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Retrieved start/end time of jobs in JobDAO

parent 82291316
No related branches found
No related tags found
No related merge requests found
Pipeline #2089 passed
......@@ -51,8 +51,8 @@ public class JobDAO {
public void createJob(JobSummary jobSummary) {
String sql =
"INSERT INTO job(job_id, owner_id, job_type, phase, job_info,"
String sql
= "INSERT INTO job(job_id, owner_id, job_type, phase, job_info,"
+ " error_message, error_type, error_has_detail, error_detail) "
+ "VALUES (?, ?, ?, ?, ?, ? ,? ,? ,?)";
......@@ -125,6 +125,9 @@ public class JobDAO {
jobSummary.setPhase(ExecutionPhase.fromValue(rs.getString("phase")));
jobSummary.setJobInfo(getJobPayload(rs.getString("job_info")));
jobSummary.setResults(getResults(rs.getString("results")));
jobSummary.setCreationTime(toXMLGregorianCalendar(rs.getTimestamp("creation_time")));
jobSummary.setStartTime(toXMLGregorianCalendar(rs.getTimestamp("start_time")));
jobSummary.setEndTime(toXMLGregorianCalendar(rs.getTimestamp("end_time")));
// Retrieve error information if any
String errorType = rs.getString("error_type");
......@@ -265,15 +268,13 @@ public class JobDAO {
String sql = "UPDATE job SET (phase, results";
ErrorSummary errorSummary = job.getErrorSummary();
if(errorSummary != null)
{
if (errorSummary != null) {
sql += ", error_message, error_type, error_has_detail, error_detail";
}
sql += ") = (?, ?";
if(errorSummary != null)
{
if (errorSummary != null) {
sql += ", ?, ?, ?, ?";
}
......@@ -283,8 +284,7 @@ public class JobDAO {
int i = 0;
ps.setObject(++i, job.getPhase().name(), Types.OTHER);
ps.setObject(++i, toJson(job.getResults()), Types.OTHER);
if(errorSummary != null)
{
if (errorSummary != null) {
ps.setString(++i, errorSummary.getMessage());
ps.setObject(++i, errorSummary.getType().value(), Types.OTHER);
ps.setBoolean(++i, errorSummary.isHasDetail());
......@@ -303,9 +303,9 @@ public class JobDAO {
}
public static XMLGregorianCalendar toXMLGregorianCalendar(Timestamp t) {
XMLGregorianCalendar cal = null;
if (t != null) {
try {
cal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
LocalDateTime ldt = t.toLocalDateTime();
......@@ -317,10 +317,14 @@ public class JobDAO {
cal.setSecond(ldt.getSecond());
cal.setFractionalSecond(new BigDecimal("0." + ldt.getNano()));
// return calendar only if it has been fully initialized (otherwise
// toString issue could appear); return null in other cases.
return cal;
} catch (Exception e) {
LOG.error("Error while generating XMLGregorianCalendar", e);
}
}
return cal;
return null;
}
}
......@@ -29,6 +29,8 @@ import net.ivoa.xml.uws.v1.Jobs;
import it.inaf.oats.vospace.exception.ErrorSummaryFactory;
import it.inaf.oats.vospace.exception.PermissionDeniedException;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {DataSourceConfig.class})
......@@ -80,11 +82,16 @@ public class JobDAOTest {
// uses the job retrieved from DAO to perform the update (reproduced a bug in job update)
job = dao.getJob("123").get();
assertNotNull(job.getCreationTime());
assertNull(job.getStartTime());
job.setPhase(ExecutionPhase.EXECUTING);
dao.updateJob(job);
assertEquals(ExecutionPhase.EXECUTING, dao.getJob("123").get().getPhase());
job = dao.getJob("123").get();
assertEquals(ExecutionPhase.EXECUTING, job.getPhase());
assertNotNull(job.getStartTime());
assertNull(job.getEndTime());
}
@Test
......@@ -143,6 +150,7 @@ public class JobDAOTest {
JobSummary retrievedJob = retrievedJobOpt.get();
assertEquals(ExecutionPhase.ERROR, retrievedJob.getPhase());
assertTrue(areEqual(job.getErrorSummary(), retrievedJob.getErrorSummary()));
assertNotNull(retrievedJob.getEndTime());
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment