Commit e28aa4c6 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Merge origin/master into copyNode

parents 1bb3fa27 7a9d688e
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -41,12 +41,7 @@ public class FileServiceClient {

    public String startArchiveJob(Transfer transfer, String jobId) {

        if (transfer.getTarget().size() != 1) {
            throw new IllegalArgumentException("Target size is " + transfer.getTarget().size());
        }

        String target = transfer.getTarget().get(0)
                .substring("vos://".length() + authority.length());
        String target = transfer.getTarget().substring("vos://".length() + authority.length());

        String viewUri = transfer.getView().getUri();

+21 −12
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
package it.inaf.oats.vospace;

import it.inaf.ia2.aa.data.User;
import it.inaf.oats.vospace.datamodel.Views;
import it.inaf.oats.vospace.exception.InternalFaultException;
import it.inaf.oats.vospace.persistence.JobDAO;
import net.ivoa.xml.uws.v1.ExecutionPhase;
@@ -17,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.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import javax.servlet.http.HttpServletRequest;
@@ -96,7 +98,7 @@ public class JobService {
            Transfer transfer = uriService.getTransfer(job);

            ExecutionPhase phase;
            if (transfer.getProtocols().stream().anyMatch(p -> "ia2:async-recall".equals(p.getUri()))) {
            if (isAsyncRecall(transfer)) {
                // Async recall from tape jobs are queued. They will be started by VOSpace transfer service
                phase = ExecutionPhase.QUEUED;
            } else {
@@ -138,16 +140,15 @@ public class JobService {

    private Transfer handlePullToVoSpace(JobSummary job, Transfer transfer) {

        for (Protocol protocol : transfer.getProtocols()) {
            switch (protocol.getUri()) {
                case "ia2:async-recall":
        if (isAsyncRecall(transfer)) {
            asyncTransfService.startJob(job);
            return transfer;
                case "ivo://ivoa.net/vospace/core#httpget":
                    if (transfer.getTarget().size() != 1) {
                        throw new InvalidArgumentException("Invalid target size for pullToVoSpace: " + transfer.getTarget().size());
        }
                    String nodeUri = transfer.getTarget().get(0);

        for (Protocol protocol : transfer.getProtocols()) {
            switch (protocol.getUri()) {
                case "ivo://ivoa.net/vospace/core#httpget":
                    String nodeUri = transfer.getTarget();
                    String contentUri = protocol.getEndpoint();
                    uriService.setNodeRemoteLocation(nodeUri, contentUri);
                    Transfer negotiatedTransfer = uriService.getNegotiatedTransfer(job, transfer);
@@ -164,6 +165,11 @@ public class JobService {
        throw new InvalidArgumentException("Transfer contains no protocols");
    }

    private boolean isAsyncRecall(Transfer transfer) {
        return transfer.getView() != null
                && Views.ASYNC_RECALL_VIEW_URI.equals(transfer.getView().getUri());
    }
    
    private void handleMoveNode(JobSummary jobSummary, Transfer transfer) {
        // User data must be extracted before starting the new thread
        // to avoid the "No thread-bound request found" exception
@@ -222,8 +228,9 @@ public class JobService {
     * compliance with specifications
     *
     */
    public void createSyncJobResult(JobSummary job) {
    public Optional<VoSpaceErrorSummarizableException> createSyncJobResult(JobSummary job) {
        Transfer negotiatedTransfer = null;
        VoSpaceErrorSummarizableException exception = null;
        try {
            Transfer transfer = uriService.getTransfer(job);
            negotiatedTransfer = uriService.getNegotiatedTransfer(job, transfer);
@@ -234,14 +241,16 @@ public class JobService {
            job.setPhase(ExecutionPhase.ERROR);
            stripProtocols(job, negotiatedTransfer);
            job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(e));
            exception = e;
        } catch (Exception e) {
            job.setPhase(ExecutionPhase.ERROR);
            stripProtocols(job, negotiatedTransfer);
            job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(
                    new InternalFaultException(e)));
            exception = new InternalFaultException(e);
            job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(exception));
        } finally {
            jobDAO.createJob(job, negotiatedTransfer);
        }
        return Optional.ofNullable(exception);
    }
    
    private void stripProtocols(JobSummary job, Transfer negotiatedTransfer) {
@@ -265,7 +274,7 @@ public class JobService {
            case pushToVoSpace:
                ResultReference dataNodeRef = new ResultReference();
                dataNodeRef.setId("dataNode");
                dataNodeRef.setHref(transfer.getTarget().get(0));
                dataNodeRef.setHref(transfer.getTarget());
                jobSummary.getResults().add(dataNodeRef);
                break;
        }
+1 −6
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ package it.inaf.oats.vospace;
import it.inaf.ia2.aa.data.User;
import it.inaf.oats.vospace.datamodel.NodeUtils;
import it.inaf.oats.vospace.exception.InternalFaultException;
import it.inaf.oats.vospace.exception.InvalidArgumentException;
import it.inaf.oats.vospace.exception.NodeBusyException;
import it.inaf.oats.vospace.exception.NodeNotFoundException;
import it.inaf.oats.vospace.exception.PermissionDeniedException;
@@ -33,12 +32,8 @@ public class MoveService extends AbstractNodeService {
    @Transactional(rollbackFor = { Exception.class }, isolation = Isolation.REPEATABLE_READ)
    public void processMoveJob(Transfer transfer, User user) {

        if (transfer.getTarget().size() != 1) {
            throw new InvalidArgumentException("Invalid target size for moveNode: " + transfer.getTarget().size());
        }

        // Get Source Vos Path
        String sourcePath = URIUtils.returnVosPathFromNodeURI(transfer.getTarget().get(0), authority);
        String sourcePath = URIUtils.returnVosPathFromNodeURI(transfer.getTarget(), authority);

        // Get Destination Vos Path (it's in transfer direction)
        String destinationPath = URIUtils.returnVosPathFromNodeURI(transfer.getDirection(), authority);
+4 −8
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ public class TransferController {
            @RequestParam("DIRECTION") String direction, @RequestParam("PROTOCOL") String protocolUris, User principal) {

        Transfer transfer = new Transfer();
        transfer.setTarget(Arrays.asList(target));
        transfer.setTarget(target);
        transfer.setDirection(direction);

        // CADC client sends multiple protocol parameters and Spring join them using a comma separator.
@@ -93,16 +93,12 @@ public class TransferController {
        }

        JobSummary jobSummary = newJobSummary(transfer, principal);
        jobService.createSyncJobResult(jobSummary);

        if (jobSummary.getErrorSummary() != null) {
            // TODO: decide how to hanlde HTTP error codes
        jobService.createSyncJobResult(jobSummary).ifPresent(ex -> {
            // If an error occurs with the synchronous convenience mode where the preferred endpoint
            // is immediately returned as a redirect, the error information is returned directly in 
            // the response body with the associated HTTP status code. 
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body(jobSummary.getErrorSummary().getMessage());
        }
            throw ex;
        });

        // Behaves as if REQUEST=redirect was set, for compatibility with CADC client
        String endpoint = transfer.getProtocols().get(0).getEndpoint();
+2 −7
Original line number Diff line number Diff line
@@ -144,13 +144,8 @@ public class UriService {
    }

    private String getEndpoint(JobSummary job, Transfer transfer) {
        boolean isArchiveView = isArchiveView(transfer);

        if (!isArchiveView && transfer.getTarget().size() != 1) {
            throw new InvalidArgumentException("Invalid target size: " + transfer.getTarget().size());
        }

        String relativePath = URIUtils.returnVosPathFromNodeURI(transfer.getTarget().get(0), authority);
        String relativePath = URIUtils.returnVosPathFromNodeURI(transfer.getTarget(), authority);

        User user = (User) servletRequest.getUserPrincipal();
        String creator = user.getName();
@@ -183,7 +178,7 @@ public class UriService {
            throw new NodeBusyException(relativePath);
        }

        if (isArchiveView) {
        if (isArchiveView(transfer)) {
            return fileServiceClient.startArchiveJob(transfer, job.getJobId());
        }

Loading