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