Commit 33db3810 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Implemented basic pullToVoSpace for tape recall

parent e3c3a2fa
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -81,6 +81,11 @@
            <version>2.0.0-SNAPSHOT</version>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
        
        <!-- Embedded PostgreSQL: -->
        <dependency>
            <groupId>com.opentable.components</groupId>
@@ -116,6 +121,25 @@
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.6</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

+61 −0
Original line number Diff line number Diff line
package it.inaf.oats.vospace;

import it.inaf.oats.vospace.persistence.JobDAO;
import net.ivoa.xml.uws.v1.ExecutionPhase;
import net.ivoa.xml.uws.v1.JobSummary;
import net.ivoa.xml.vospace.v2.Transfer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class JobService {

    @Autowired
    private JobDAO jobDAO;

    @Autowired
    private UriService uriService;

    @Autowired
    private TapeService tapeService;

    enum JobType {
        pullToVoSpace,
        pullFromVoSpace,
        moveNode,
        copyNode
    }

    public void startJob(JobSummary job) {

        switch (getJobType(job)) {
            case pullToVoSpace:
                handlePullToVoSpace(job);
                break;
            case pullFromVoSpace:
                handlePullFromVoSpace(job);
                break;
            default:
                throw new UnsupportedOperationException("Not implemented yet");
        }
    }

    private void handlePullToVoSpace(JobSummary job) {
        // TODO: check protocol
        tapeService.startJob(job);
    }

    private void handlePullFromVoSpace(JobSummary job) {
        job.setPhase(ExecutionPhase.EXECUTING);
        uriService.setTransferJobResult(job);
        jobDAO.updateJob(job);
    }

    private JobType getJobType(JobSummary job) {

        // TODO: check types
        Transfer transfer = (Transfer) job.getJobInfo().getAny().get(0);

        return JobType.valueOf(transfer.getDirection());
    }
}
+35 −0
Original line number Diff line number Diff line
package it.inaf.oats.vospace;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.UncheckedIOException;
import net.ivoa.xml.uws.v1.JobSummary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TapeService {

    private static final Logger LOG = LoggerFactory.getLogger(TapeService.class);

    @Autowired
    private RabbitTemplate template;

    private static final ObjectMapper MAPPER = new ObjectMapper();

    public JobSummary startJob(JobSummary job) {
        try {
            byte[] message = MAPPER.writeValueAsBytes(job);
            byte[] result = (byte[]) template.convertSendAndReceive("start_job_queue", message);

            LOG.trace("Tape transfer service answered:\n{}", new String(result));

            return MAPPER.readValue(result, JobSummary.class);
        } catch (IOException ex) {
            throw new UncheckedIOException(ex);
        }
    }
}
+12 −8
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package it.inaf.oats.vospace;

import it.inaf.ia2.aa.data.User;
import it.inaf.oats.vospace.persistence.JobDAO;
import java.util.Optional;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import net.ivoa.xml.uws.v1.ExecutionPhase;
@@ -29,12 +30,13 @@ public class TransferController {
    private HttpServletRequest request;

    @Autowired
    private UriService uriService;
    private JobService jobService;

    @PostMapping(value = "/transfers",
            consumes = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE},
            produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})
    public ResponseEntity<?> postTransfer(@RequestBody Transfer transfer, User principal) {
            consumes = {MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_JSON_VALUE},
            produces = {MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})
    public ResponseEntity<?> postTransfer(@RequestBody Transfer transfer,
            @RequestParam(value = "PHASE", required = false) Optional<String> phase, User principal) {

        String jobId = UUID.randomUUID().toString().replace("-", "");

@@ -48,10 +50,14 @@ public class TransferController {

        jobDAO.createJob(jobSummary);

        if (phase.isPresent() && "RUN".equals(phase.get())) {
            jobService.startJob(jobSummary);
        }

        return getJobRedirect(jobId);
    }

    @GetMapping(value = "/transfers/{jobId}", produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})
    @GetMapping(value = "/transfers/{jobId}", produces = {MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})
    public ResponseEntity<JobSummary> getJob(@PathVariable("jobId") String jobId) {
        return jobDAO.getJob(jobId).map(j -> ResponseEntity.ok(j)).orElse(ResponseEntity.notFound().build());
    }
@@ -67,9 +73,7 @@ public class TransferController {
            // TODO: check allowed job phase transitions
            switch (phase) {
                case "RUN":
                    job.setPhase(ExecutionPhase.EXECUTING);
                    uriService.setTransferJobResult(job);
                    jobDAO.updateJob(job);
                    jobService.startJob(job);
                    break;
                case "ABORT":
                    throw new UnsupportedOperationException("Not implemented yet");
+1 −1

File changed.

Contains only whitespace changes.