Commit 51c0c90b authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Added call to file service for copyNode

parent dacaa79d
Loading
Loading
Loading
Loading
+10 −3
Original line number Original line Diff line number Diff line
@@ -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 {
                    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);
+60 −1
Original line number Original line Diff line number Diff line
@@ -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;
+0 −4
Original line number Original line Diff line number Diff line
@@ -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;
            });
            });