Skip to content
Snippets Groups Projects
Commit a1c4d3f5 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Added call to file service for copyNode

parent b9fb7a45
No related branches found
No related tags found
No related merge requests found
...@@ -18,11 +18,15 @@ import org.springframework.stereotype.Service; ...@@ -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) {
...@@ -85,6 +89,9 @@ public class CopyService extends AbstractNodeService { ...@@ -85,6 +89,9 @@ 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);
......
...@@ -87,6 +87,65 @@ public class FileServiceClient { ...@@ -87,6 +87,65 @@ public class FileServiceClient {
}, 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 {
private String type; private String type;
......
...@@ -190,10 +190,6 @@ public class JobService { ...@@ -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;
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment