Loading src/main/java/it/inaf/oats/vospace/JobService.java +39 −44 Original line number Diff line number Diff line Loading @@ -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)) { Loading @@ -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) { Loading src/test/java/it/inaf/oats/vospace/TransferControllerTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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/.*")); } Loading Loading
src/main/java/it/inaf/oats/vospace/JobService.java +39 −44 Original line number Diff line number Diff line Loading @@ -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)) { Loading @@ -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) { Loading
src/test/java/it/inaf/oats/vospace/TransferControllerTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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/.*")); } Loading