Skip to content
Snippets Groups Projects
Commit d6970783 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Minor refactoring of error handling code in JobService::startJob +

added update job phase on switch to EXECUTING
parent 330ec0de
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,10 @@ public class JobService {
private void startJob(JobSummary job) {
try {
job.setPhase(ExecutionPhase.EXECUTING);
jobDAO.updateJob(job);
Transfer transfer = uriService.getTransfer(job);
switch (getJobType(transfer)) {
......@@ -60,47 +64,38 @@ public class JobService {
default:
throw new UnsupportedOperationException("Not implemented yet");
}
job.setPhase(ExecutionPhase.COMPLETED);
} catch (VoSpaceErrorSummarizableException e) {
job.setPhase(ExecutionPhase.ERROR);
job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(e.getFault()));
} finally {
jobDAO.updateJob(job);
}
}
private void handlePullToVoSpace(JobSummary job, Transfer transfer) {
try {
for (Protocol protocol : transfer.getProtocols()) {
switch (protocol.getUri()) {
case "ia2:async-recall":
asyncTransfService.startJob(job);
// ASK IF IT's OK neglect phase update.
return;
case "ivo://ivoa.net/vospace/core#httpget":
String nodeUri = transfer.getTarget();
String contentUri = protocol.getEndpoint();
uriService.setNodeRemoteLocation(nodeUri, contentUri);
uriService.setTransferJobResult(job, transfer);
job.setPhase(ExecutionPhase.COMPLETED);
jobDAO.updateJob(job);
return;
default:
throw new InternalFaultException("Unsupported pullToVoSpace protocol: " + protocol.getUri());
}
}
} catch (VoSpaceErrorSummarizableException e) {
job.setPhase(ExecutionPhase.ERROR);
job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(e.getFault()));
jobDAO.updateJob(job);
}
}
private void handleVoSpaceUrlsListResult(JobSummary job, Transfer transfer) {
try {
job.setPhase(ExecutionPhase.EXECUTING);
uriService.setTransferJobResult(job, transfer);
job.setPhase(ExecutionPhase.COMPLETED);
// Need to catch other exceptions too to avoid inconsistent job status
} catch (VoSpaceErrorSummarizableException e) {
job.setPhase(ExecutionPhase.ERROR);
job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(e.getFault()));
} finally {
jobDAO.updateJob(job);
}
}
private JobType getJobType(Transfer transfer) {
......
......@@ -143,7 +143,7 @@ public class TransferControllerTest {
verify(nodeDao, times(1)).setNodeLocation(eq("/portalnode"), eq(2), eq("lbcr.20130512.060722.fits.gz"));
verify(jobDao, times(1)).updateJob(argThat(j -> {
verify(jobDao, times(2)).updateJob(argThat(j -> {
assertTrue(j.getResults().get(0).getHref().startsWith("http://archive.lbto.org"));
assertEquals(ExecutionPhase.COMPLETED, j.getPhase());
return true;
......@@ -187,7 +187,7 @@ public class TransferControllerTest {
.andExpect(status().is3xxRedirection())
.andReturn().getResponse().getHeader("Location");
verify(jobDao, times(1)).updateJob(any());
verify(jobDao, times(2)).updateJob(any());
assertThat(redirect, matchesPattern("^/transfers/.*"));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment