Loading src/main/java/it/inaf/oats/vospace/CopyService.java +10 −3 Original line number Original line Diff line number Diff line Loading @@ -18,11 +18,15 @@ 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 String processCopyNodes(Transfer transfer, String jobId, User user) { Loading @@ -47,11 +51,11 @@ public class CopyService extends AbstractNodeService { if (destinationPath.startsWith(sourcePath + "/")) { if (destinationPath.startsWith(sourcePath + "/")) { throw new IllegalArgumentException("Cannot copy node to a subdirectory of its own path"); throw new IllegalArgumentException("Cannot copy node to a subdirectory of its own path"); } } // Check if destination equals parent path of source // Check if destination equals parent path of source if(NodeUtils.getParentPath(sourcePath).equals(destinationPath)){ if (NodeUtils.getParentPath(sourcePath).equals(destinationPath)) { throw new IllegalArgumentException("Cannot duplicate node at same path without renaming it"); throw new IllegalArgumentException("Cannot duplicate node at same path without renaming it"); } } try { try { Loading Loading @@ -84,6 +88,9 @@ public class CopyService extends AbstractNodeService { nodeDao.copyBranch( nodeDao.copyBranch( 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 Loading src/main/java/it/inaf/oats/vospace/FileServiceClient.java +60 −1 Original line number Original line Diff line number Diff line Loading @@ -79,13 +79,72 @@ public class FileServiceClient { headers.setBearerAuth(token); headers.setBearerAuth(token); } } headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentType(MediaType.APPLICATION_JSON); try ( OutputStream os = req.getBody()) { try (OutputStream os = req.getBody()) { MAPPER.writeValue(os, archiveRequest); MAPPER.writeValue(os, archiveRequest); } } }, res -> { }, res -> { return res.getHeaders().getLocation().toString(); return res.getHeaders().getLocation().toString(); }, new Object[]{}); }, new Object[]{}); } } public void startFileCopyJob(String sourceVosPath, String destiantionVosPath, String jobId, User user) { CopyRequest copyRequest = new CopyRequest(); copyRequest.setJobId(jobId); copyRequest.setSourceRootVosPath(sourceVosPath); copyRequest.setDestinationRootVosPath(destiantionVosPath); String url = fileServiceUrl + "/copy"; String token = user.getAccessToken(); restTemplate.execute(url, HttpMethod.POST, req -> { HttpHeaders headers = req.getHeaders(); if (token != null) { headers.setBearerAuth(token); } headers.setContentType(MediaType.APPLICATION_JSON); try (OutputStream os = req.getBody()) { MAPPER.writeValue(os, copyRequest); } }, res -> { return null; }, new Object[]{}); } public static class CopyRequest { private String jobId; private String sourceRootVosPath; private String destinationRootVosPath; public String getJobId() { return jobId; } public void setJobId(String jobId) { this.jobId = jobId; } public String getSourceRootVosPath() { return sourceRootVosPath; } public void setSourceRootVosPath(String sourceRootVosPath) { this.sourceRootVosPath = sourceRootVosPath; } public String getDestinationRootVosPath() { return destinationRootVosPath; } public void setDestinationRootVosPath(String destinationRootVosPath) { this.destinationRootVosPath = destinationRootVosPath; } } public static class ArchiveRequest { public static class ArchiveRequest { Loading src/main/java/it/inaf/oats/vospace/JobService.java +0 −4 Original line number Original line Diff line number Diff line Loading @@ -190,10 +190,6 @@ public class JobService { CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> { handleJobErrors(jobSummary, job -> { handleJobErrors(jobSummary, job -> { copyService.processCopyNodes(transfer, jobSummary.getJobId(), user); copyService.processCopyNodes(transfer, jobSummary.getJobId(), user); // add file service copy logic // the file service part will unlock nodes and set job phase // to completed return null; return null; }); }); Loading Loading
src/main/java/it/inaf/oats/vospace/CopyService.java +10 −3 Original line number Original line Diff line number Diff line Loading @@ -18,11 +18,15 @@ 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 String processCopyNodes(Transfer transfer, String jobId, User user) { Loading @@ -47,11 +51,11 @@ public class CopyService extends AbstractNodeService { if (destinationPath.startsWith(sourcePath + "/")) { if (destinationPath.startsWith(sourcePath + "/")) { throw new IllegalArgumentException("Cannot copy node to a subdirectory of its own path"); throw new IllegalArgumentException("Cannot copy node to a subdirectory of its own path"); } } // Check if destination equals parent path of source // Check if destination equals parent path of source if(NodeUtils.getParentPath(sourcePath).equals(destinationPath)){ if (NodeUtils.getParentPath(sourcePath).equals(destinationPath)) { throw new IllegalArgumentException("Cannot duplicate node at same path without renaming it"); throw new IllegalArgumentException("Cannot duplicate node at same path without renaming it"); } } try { try { Loading Loading @@ -84,6 +88,9 @@ public class CopyService extends AbstractNodeService { nodeDao.copyBranch( nodeDao.copyBranch( 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 Loading
src/main/java/it/inaf/oats/vospace/FileServiceClient.java +60 −1 Original line number Original line Diff line number Diff line Loading @@ -79,13 +79,72 @@ public class FileServiceClient { headers.setBearerAuth(token); headers.setBearerAuth(token); } } headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentType(MediaType.APPLICATION_JSON); try ( OutputStream os = req.getBody()) { try (OutputStream os = req.getBody()) { MAPPER.writeValue(os, archiveRequest); MAPPER.writeValue(os, archiveRequest); } } }, res -> { }, res -> { return res.getHeaders().getLocation().toString(); return res.getHeaders().getLocation().toString(); }, new Object[]{}); }, new Object[]{}); } } public void startFileCopyJob(String sourceVosPath, String destiantionVosPath, String jobId, User user) { CopyRequest copyRequest = new CopyRequest(); copyRequest.setJobId(jobId); copyRequest.setSourceRootVosPath(sourceVosPath); copyRequest.setDestinationRootVosPath(destiantionVosPath); String url = fileServiceUrl + "/copy"; String token = user.getAccessToken(); restTemplate.execute(url, HttpMethod.POST, req -> { HttpHeaders headers = req.getHeaders(); if (token != null) { headers.setBearerAuth(token); } headers.setContentType(MediaType.APPLICATION_JSON); try (OutputStream os = req.getBody()) { MAPPER.writeValue(os, copyRequest); } }, res -> { return null; }, new Object[]{}); } public static class CopyRequest { private String jobId; private String sourceRootVosPath; private String destinationRootVosPath; public String getJobId() { return jobId; } public void setJobId(String jobId) { this.jobId = jobId; } public String getSourceRootVosPath() { return sourceRootVosPath; } public void setSourceRootVosPath(String sourceRootVosPath) { this.sourceRootVosPath = sourceRootVosPath; } public String getDestinationRootVosPath() { return destinationRootVosPath; } public void setDestinationRootVosPath(String destinationRootVosPath) { this.destinationRootVosPath = destinationRootVosPath; } } public static class ArchiveRequest { public static class ArchiveRequest { Loading
src/main/java/it/inaf/oats/vospace/JobService.java +0 −4 Original line number Original line Diff line number Diff line Loading @@ -190,10 +190,6 @@ public class JobService { CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> { handleJobErrors(jobSummary, job -> { handleJobErrors(jobSummary, job -> { copyService.processCopyNodes(transfer, jobSummary.getJobId(), user); copyService.processCopyNodes(transfer, jobSummary.getJobId(), user); // add file service copy logic // the file service part will unlock nodes and set job phase // to completed return null; return null; }); }); Loading