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 { ...@@ -47,6 +47,10 @@ public class JobService {
private void startJob(JobSummary job) { private void startJob(JobSummary job) {
try {
job.setPhase(ExecutionPhase.EXECUTING);
jobDAO.updateJob(job);
Transfer transfer = uriService.getTransfer(job); Transfer transfer = uriService.getTransfer(job);
switch (getJobType(transfer)) { switch (getJobType(transfer)) {
...@@ -60,47 +64,38 @@ public class JobService { ...@@ -60,47 +64,38 @@ public class JobService {
default: default:
throw new UnsupportedOperationException("Not implemented yet"); 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) { private void handlePullToVoSpace(JobSummary job, Transfer transfer) {
try {
for (Protocol protocol : transfer.getProtocols()) { for (Protocol protocol : transfer.getProtocols()) {
switch (protocol.getUri()) { switch (protocol.getUri()) {
case "ia2:async-recall": case "ia2:async-recall":
asyncTransfService.startJob(job); asyncTransfService.startJob(job);
// ASK IF IT's OK neglect phase update.
return; return;
case "ivo://ivoa.net/vospace/core#httpget": case "ivo://ivoa.net/vospace/core#httpget":
String nodeUri = transfer.getTarget(); String nodeUri = transfer.getTarget();
String contentUri = protocol.getEndpoint(); String contentUri = protocol.getEndpoint();
uriService.setNodeRemoteLocation(nodeUri, contentUri); uriService.setNodeRemoteLocation(nodeUri, contentUri);
uriService.setTransferJobResult(job, transfer); uriService.setTransferJobResult(job, transfer);
job.setPhase(ExecutionPhase.COMPLETED);
jobDAO.updateJob(job);
return; return;
default: default:
throw new InternalFaultException("Unsupported pullToVoSpace protocol: " + protocol.getUri()); 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) { private void handleVoSpaceUrlsListResult(JobSummary job, Transfer transfer) {
try {
job.setPhase(ExecutionPhase.EXECUTING);
uriService.setTransferJobResult(job, transfer); 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) { private JobType getJobType(Transfer transfer) {
......
...@@ -143,7 +143,7 @@ public class TransferControllerTest { ...@@ -143,7 +143,7 @@ public class TransferControllerTest {
verify(nodeDao, times(1)).setNodeLocation(eq("/portalnode"), eq(2), eq("lbcr.20130512.060722.fits.gz")); 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")); assertTrue(j.getResults().get(0).getHref().startsWith("http://archive.lbto.org"));
assertEquals(ExecutionPhase.COMPLETED, j.getPhase()); assertEquals(ExecutionPhase.COMPLETED, j.getPhase());
return true; return true;
...@@ -187,7 +187,7 @@ public class TransferControllerTest { ...@@ -187,7 +187,7 @@ public class TransferControllerTest {
.andExpect(status().is3xxRedirection()) .andExpect(status().is3xxRedirection())
.andReturn().getResponse().getHeader("Location"); .andReturn().getResponse().getHeader("Location");
verify(jobDao, times(1)).updateJob(any()); verify(jobDao, times(2)).updateJob(any());
assertThat(redirect, matchesPattern("^/transfers/.*")); 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