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

Stripped protocols also from negotiated transfer result in case of error on...

Stripped protocols also from negotiated transfer result in case of error on synchronous transfer endpoint
parent 5635ac9c
No related branches found
No related tags found
No related merge requests found
...@@ -209,11 +209,11 @@ public class JobService { ...@@ -209,11 +209,11 @@ public class JobService {
// Need to catch other exceptions too to avoid inconsistent job status // Need to catch other exceptions too to avoid inconsistent job status
} catch (VoSpaceErrorSummarizableException e) { } catch (VoSpaceErrorSummarizableException e) {
job.setPhase(ExecutionPhase.ERROR); job.setPhase(ExecutionPhase.ERROR);
uriService.getTransfer(job).getProtocols().clear(); stripProtocols(job, negotiatedTransfer);
job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(e)); job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(e));
} catch (Exception e) { } catch (Exception e) {
job.setPhase(ExecutionPhase.ERROR); job.setPhase(ExecutionPhase.ERROR);
uriService.getTransfer(job).getProtocols().clear(); stripProtocols(job, negotiatedTransfer);
job.setErrorSummary(ErrorSummaryFactory.newErrorSummary( job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(
new InternalFaultException(e))); new InternalFaultException(e)));
} finally { } finally {
...@@ -221,6 +221,13 @@ public class JobService { ...@@ -221,6 +221,13 @@ public class JobService {
} }
} }
private void stripProtocols(JobSummary job, Transfer negotiatedTransfer) {
uriService.getTransfer(job).getProtocols().clear();
if (negotiatedTransfer != null) {
negotiatedTransfer.getProtocols().clear();
}
}
private void setJobResults(JobSummary jobSummary, Transfer transfer) { private void setJobResults(JobSummary jobSummary, Transfer transfer) {
String baseUrl = servletRequest.getRequestURL().substring(0, String baseUrl = servletRequest.getRequestURL().substring(0,
servletRequest.getRequestURL().indexOf(servletRequest.getContextPath())); servletRequest.getRequestURL().indexOf(servletRequest.getContextPath()));
......
...@@ -16,6 +16,8 @@ import net.ivoa.xml.uws.v1.JobSummary; ...@@ -16,6 +16,8 @@ import net.ivoa.xml.uws.v1.JobSummary;
import net.ivoa.xml.vospace.v2.Protocol; import net.ivoa.xml.vospace.v2.Protocol;
import net.ivoa.xml.vospace.v2.Transfer; import net.ivoa.xml.vospace.v2.Transfer;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
...@@ -108,18 +110,42 @@ public class JobServiceTest { ...@@ -108,18 +110,42 @@ public class JobServiceTest {
@Test @Test
public void testSyncJobResultVoSpaceError() { public void testSyncJobResultVoSpaceError() {
when(uriService.getTransfer(any())).thenReturn(getPullFromVoSpaceHttpTransfer()); Transfer transfer = getPullFromVoSpaceHttpTransfer();
assertFalse(transfer.getProtocols().isEmpty());
when(uriService.getTransfer(any())).thenReturn(transfer);
doThrow(new NodeBusyException("/foo")).when(uriService).getNegotiatedTransfer(any(), any()); doThrow(new NodeBusyException("/foo")).when(uriService).getNegotiatedTransfer(any(), any());
jobService.createSyncJobResult(new JobSummary()); jobService.createSyncJobResult(new JobSummary());
verify(jobDAO, times(1)).createJob(argThat(j -> ExecutionPhase.ERROR.equals(j.getPhase())), any()); verify(jobDAO, times(1)).createJob(argThat(j -> ExecutionPhase.ERROR.equals(j.getPhase())), any());
assertTrue(transfer.getProtocols().isEmpty());
} }
@Test @Test
public void testSyncJobResultUnexpectedError() { public void testSyncJobResultUnexpectedError() {
when(uriService.getTransfer(any())).thenReturn(getPullFromVoSpaceHttpTransfer()); Transfer transfer = getPullFromVoSpaceHttpTransfer();
assertFalse(transfer.getProtocols().isEmpty());
when(uriService.getTransfer(any())).thenReturn(transfer);
doThrow(new NullPointerException()).when(uriService).getNegotiatedTransfer(any(), any()); doThrow(new NullPointerException()).when(uriService).getNegotiatedTransfer(any(), any());
jobService.createSyncJobResult(new JobSummary()); jobService.createSyncJobResult(new JobSummary());
verify(jobDAO, times(1)).createJob(argThat(j -> ExecutionPhase.ERROR.equals(j.getPhase())), any()); verify(jobDAO, times(1)).createJob(argThat(j -> ExecutionPhase.ERROR.equals(j.getPhase())), any());
assertTrue(transfer.getProtocols().isEmpty());
}
@Test
public void testSyncJobResultErrorAfterNegotiatedTransfer() {
Transfer transfer = getPullFromVoSpaceHttpTransfer();
assertFalse(transfer.getProtocols().isEmpty());
when(uriService.getTransfer(any())).thenReturn(transfer);
Transfer negotiatedTransfer = getPullFromVoSpaceHttpTransfer();
assertFalse(negotiatedTransfer.getProtocols().isEmpty());
when(uriService.getNegotiatedTransfer(any(), any())).thenReturn(negotiatedTransfer);
doThrow(new NullPointerException()).when(servletRequest).getContextPath();
jobService.createSyncJobResult(new JobSummary());
verify(jobDAO, times(1)).createJob(argThat(j -> ExecutionPhase.ERROR.equals(j.getPhase())), any());
assertTrue(transfer.getProtocols().isEmpty());
assertTrue(negotiatedTransfer.getProtocols().isEmpty());
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment