Skip to content
Snippets Groups Projects
Commit 7184b385 authored by nfcalabria's avatar nfcalabria
Browse files

Bugfix: call file service after DB copy transaction has been committed

parent a1c4d3f5
Branches
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ import it.inaf.oats.vospace.exception.NodeBusyException;
import it.inaf.oats.vospace.exception.NodeNotFoundException;
import it.inaf.oats.vospace.exception.PermissionDeniedException;
import it.inaf.oats.vospace.persistence.NodeDAO.ShortNodeDescriptor;
import java.util.List;
import java.util.Optional;
import net.ivoa.xml.vospace.v2.Transfer;
import org.springframework.dao.CannotSerializeTransactionException;
......@@ -18,17 +19,14 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
@Service
@EnableTransactionManagement
public class CopyService extends AbstractNodeService {
@Autowired
private FileServiceClient fileServiceClient;
@Transactional(rollbackFor = {Exception.class}, isolation = Isolation.REPEATABLE_READ)
public String processCopyNodes(Transfer transfer, String jobId, User user) {
public List<String> processCopyNodes(Transfer transfer, String jobId, User user) {
// Get Source Vos Path
String sourcePath = URIUtils.returnVosPathFromNodeURI(transfer.getTarget(), authority);
......@@ -89,15 +87,12 @@ public class CopyService extends AbstractNodeService {
sourcePath,
destinationCopyRoot);
// Call file service and command copy
fileServiceClient.startFileCopyJob(sourcePath, destinationCopyRoot, jobId, user);
} catch (CannotSerializeTransactionException ex) {
// Concurrent transactions attempted to modify this set of nodes
throw new NodeBusyException(sourcePath);
}
return destinationCopyRoot;
return List.of(sourcePath, destinationCopyRoot);
}
......
......@@ -18,6 +18,7 @@ import it.inaf.oats.vospace.exception.InvalidArgumentException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import it.inaf.oats.vospace.exception.VoSpaceErrorSummarizableException;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
......@@ -49,6 +50,9 @@ public class JobService {
@Autowired
private HttpServletRequest servletRequest;
@Autowired
private FileServiceClient fileServiceClient;
public enum JobDirection {
pullToVoSpace,
pullFromVoSpace,
......@@ -189,7 +193,10 @@ public class JobService {
User user = (User) servletRequest.getUserPrincipal();
CompletableFuture.runAsync(() -> {
handleJobErrors(jobSummary, job -> {
copyService.processCopyNodes(transfer, jobSummary.getJobId(), user);
String jobId = jobSummary.getJobId();
List<String> sourceAndDestination = copyService.processCopyNodes(transfer, jobId, user);
// Call file service and command copy
fileServiceClient.startFileCopyJob(sourceAndDestination.get(0), sourceAndDestination.get(1), jobId, user);
return null;
});
......
......@@ -141,7 +141,7 @@ public class CopyServiceTest {
// copy
String copyDestination
= copyService.processCopyNodes(getTransfer("/test3/m1", "/test4"), "job_pippo", user);
= copyService.processCopyNodes(getTransfer("/test3/m1", "/test4"), "job_pippo", user).get(1);
assertEquals("/test4/m1", copyDestination);
......@@ -176,7 +176,7 @@ public class CopyServiceTest {
// copy
String copyDestination
= copyService.processCopyNodes(getTransfer("/test3/m1/m2", "/test3/m1/m2_copy"), "job_pippo", user);
= copyService.processCopyNodes(getTransfer("/test3/m1/m2", "/test3/m1/m2_copy"), "job_pippo", user).get(1);
assertEquals("/test3/m1/m2_copy", copyDestination);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment