Search in sources :

Example 11 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class JobTest method testMarshallingWithJsonPayload.

@Test
public void testMarshallingWithJsonPayload() throws Exception {
    final String payload = "{'foo' : 'bar'}";
    Job job = new JobImpl();
    job.setPayload(payload);
    String marshalledJob = JobParser.toXml(new JaxbJob(job));
    Job unmarshalledJob = JobParser.parseJob(marshalledJob);
    assertEquals("json from unmarshalled job should remain unchanged", StringUtils.trim(payload), StringUtils.trim(unmarshalledJob.getPayload()));
}
Also used : JobImpl(org.opencastproject.job.api.JobImpl) JaxbJob(org.opencastproject.job.api.JaxbJob) Arrays.mkString(org.opencastproject.util.data.Arrays.mkString) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 12 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class AnimateServiceRestEndpoint method animate.

@POST
@Produces(MediaType.TEXT_XML)
@Path("animate")
@RestQuery(name = "animate", description = "Create animates video clip", restParameters = { @RestParameter(name = "animation", isRequired = true, type = STRING, description = "Location of to the animation"), @RestParameter(name = "arguments", isRequired = true, type = STRING, description = "Synfig command line arguments as JSON array"), @RestParameter(name = "metadata", isRequired = true, type = STRING, description = "Metadata for replacement as JSON object") }, reponses = { @RestResponse(description = "Animation created successfully", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Invalid data", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "Internal error", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "Returns the path to the generated animation video")
public Response animate(@FormParam("animation") String animation, @FormParam("arguments") String argumentsString, @FormParam("metadata") String metadataString) {
    Gson gson = new Gson();
    try {
        Map<String, String> metadata = gson.fromJson(metadataString, stringMapType);
        List<String> arguments = gson.fromJson(argumentsString, stringListType);
        logger.debug("Start animation");
        Job job = animateService.animate(new URI(animation), metadata, arguments);
        return Response.ok(new JaxbJob(job)).build();
    } catch (JsonSyntaxException | URISyntaxException | NullPointerException e) {
        logger.debug("Invalid data passed to REST endpoint:\nanimation: {}\nmetadata: {}\narguments: {})", animation, metadataString, argumentsString);
        return Response.status(Response.Status.BAD_REQUEST).build();
    } catch (AnimateServiceException e) {
        logger.error("Error animating file {}", animation, e);
        return Response.serverError().build();
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) AnimateServiceException(org.opencastproject.animate.api.AnimateServiceException) JaxbJob(org.opencastproject.job.api.JaxbJob) Gson(com.google.gson.Gson) URISyntaxException(java.net.URISyntaxException) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 13 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class YouTubePublicationRestService method retract.

@POST
@Path("/retract")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "retract", description = "Retract a media package from the youtube publication channel", returnDescription = "The job that can be used to track the retraction", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The mediapackage", type = Type.TEXT) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the retraction job") })
public Response retract(@FormParam("mediapackage") final String mediaPackageXml) {
    final Job job;
    try {
        final MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
        job = service.retract(mediapackage);
    } catch (Exception e) {
        logger.warn("Unable to retract mediapackage '{}' from YouTube: {}", mediaPackageXml, e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
    return Response.ok(new JaxbJob(job)).build();
}
Also used : JaxbJob(org.opencastproject.job.api.JaxbJob) MediaPackage(org.opencastproject.mediapackage.MediaPackage) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 14 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class ExecuteRestEndpoint method execute.

@POST
@Produces(MediaType.TEXT_XML)
@Path(ExecuteService.ENDPOINT_NAME)
@RestQuery(name = "name", description = "Executes the given command", restParameters = { @RestParameter(description = "The command to execute", isRequired = true, name = ExecuteService.EXEC_FORM_PARAM, type = RestParameter.Type.STRING), @RestParameter(description = "The arguments to the command", isRequired = true, name = ExecuteService.PARAMS_FORM_PARAM, type = RestParameter.Type.STRING), @RestParameter(description = "The estimated load placed on the system by this command", isRequired = false, name = ExecuteService.LOAD_FORM_PARAM, type = RestParameter.Type.FLOAT), @RestParameter(description = "The mediapackage to apply the command to. Either this or " + ExecuteService.INPUT_ELEM_FORM_PARAM + " are required", isRequired = false, name = ExecuteService.INPUT_MP_FORM_PARAM, type = RestParameter.Type.TEXT), @RestParameter(description = "The mediapackage element to apply the command to. Either this or " + ExecuteService.INPUT_MP_FORM_PARAM + " are required", isRequired = false, name = ExecuteService.INPUT_ELEM_FORM_PARAM, type = RestParameter.Type.TEXT), @RestParameter(description = "The mediapackage element produced by the command", isRequired = false, name = ExecuteService.OUTPUT_NAME_FORM_PARAMETER, type = RestParameter.Type.STRING), @RestParameter(description = "The type of the returned element", isRequired = false, name = ExecuteService.TYPE_FORM_PARAMETER, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "XML-encoded Job is returned.", responseCode = HttpServletResponse.SC_NO_CONTENT), @RestResponse(description = "Service unavailabe or not currently present", responseCode = HttpServletResponse.SC_SERVICE_UNAVAILABLE), @RestResponse(description = "Incorrect parameters", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "Problem executing the command or serializing the arguments/results", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response execute(@FormParam(ExecuteService.EXEC_FORM_PARAM) String exec, @FormParam(ExecuteService.PARAMS_FORM_PARAM) String params, @FormParam(ExecuteService.LOAD_FORM_PARAM) Float loadParam, @FormParam(ExecuteService.INPUT_ELEM_FORM_PARAM) String inputElementStr, @FormParam(ExecuteService.INPUT_MP_FORM_PARAM) String inputMpStr, @FormParam(ExecuteService.OUTPUT_NAME_FORM_PARAMETER) String outputFileName, @FormParam(ExecuteService.TYPE_FORM_PARAMETER) String elementTypeStr) {
    checkNotNull(service);
    try {
        MediaPackageElement.Type expectedType = null;
        if (StringUtils.isNotBlank(elementTypeStr)) {
            for (MediaPackageElement.Type candidateType : MediaPackageElement.Type.values()) if (candidateType.toString().equalsIgnoreCase(elementTypeStr)) {
                expectedType = candidateType;
                break;
            }
            if (expectedType == null) {
                logger.error("Wrong element type specified: {}", elementTypeStr);
                return Response.status(Response.Status.BAD_REQUEST).build();
            }
        }
        float load = 1.0f;
        if (loadParam != null) {
            load = loadParam;
        }
        Job retJob = null;
        if (StringUtils.isNotBlank(inputElementStr) && StringUtils.isNotBlank(inputMpStr)) {
            logger.error("Only one input MediaPackage OR input MediaPackageElement can be set at the same time");
            return Response.status(Response.Status.BAD_REQUEST).build();
        } else if (StringUtils.isNotBlank(inputElementStr)) {
            MediaPackageElement inputElement = MediaPackageElementParser.getFromXml(inputElementStr);
            retJob = service.execute(exec, params, inputElement, outputFileName, expectedType, load);
        } else if (StringUtils.isNotBlank(inputMpStr)) {
            MediaPackage inputMp = MediaPackageParser.getFromXml(inputMpStr);
            retJob = service.execute(exec, params, inputMp, outputFileName, expectedType, load);
        } else {
            logger.error("A MediaPackage OR MediaPackageElement must be provided");
            return Response.status(Response.Status.BAD_REQUEST).build();
        }
        return Response.ok(new JaxbJob(retJob)).build();
    } catch (IllegalArgumentException e) {
        logger.error("The expected element type is required if an output filename is specified");
        return Response.status(Response.Status.BAD_REQUEST).build();
    } catch (MediaPackageException e) {
        logger.error("Received excepcion: {}", e.getMessage());
        return Response.serverError().build();
    } catch (ExecuteException e) {
        logger.error("Received error from the execute service: {}", e.getMessage());
        return Response.serverError().build();
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) JaxbJob(org.opencastproject.job.api.JaxbJob) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ExecuteException(org.opencastproject.execute.api.ExecuteException) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 15 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class ServiceRegistryInMemoryImpl method createJob.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.serviceregistry.api.ServiceRegistry#createJob(java.lang.String, java.lang.String,
 *          java.util.List, java.lang.String, boolean, org.opencastproject.job.api.Job, Float)
 */
@Override
public Job createJob(String type, String operation, List<String> arguments, String payload, boolean queueable, Job parentJob, Float jobLoad) throws ServiceRegistryException {
    if (getServiceRegistrationsByType(type).size() == 0)
        logger.warn("Service " + type + " not available");
    Job job = null;
    synchronized (this) {
        job = new JobImpl(idCounter.addAndGet(1));
        if (securityService != null) {
            job.setCreator(securityService.getUser().getUsername());
            job.setOrganization(securityService.getOrganization().getId());
        }
        job.setDateCreated(new Date());
        job.setJobType(type);
        job.setOperation(operation);
        job.setArguments(arguments);
        job.setPayload(payload);
        if (queueable)
            job.setStatus(Status.QUEUED);
        else
            job.setStatus(Status.INSTANTIATED);
        if (parentJob != null)
            job.setParentJobId(parentJob.getId());
        job.setJobLoad(jobLoad);
    }
    synchronized (jobs) {
        try {
            jobs.put(job.getId(), JobParser.toXml(new JaxbJob(job)));
        } catch (IOException e) {
            throw new IllegalStateException("Error serializing job " + job, e);
        }
    }
    return job;
}
Also used : JobImpl(org.opencastproject.job.api.JobImpl) JaxbJob(org.opencastproject.job.api.JaxbJob) IOException(java.io.IOException) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Date(java.util.Date)

Aggregations

JaxbJob (org.opencastproject.job.api.JaxbJob)35 Job (org.opencastproject.job.api.Job)31 POST (javax.ws.rs.POST)26 Path (javax.ws.rs.Path)26 Produces (javax.ws.rs.Produces)26 RestQuery (org.opencastproject.util.doc.rest.RestQuery)26 MediaPackage (org.opencastproject.mediapackage.MediaPackage)14 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)10 TypeToken (com.google.gson.reflect.TypeToken)8 Gson (com.google.gson.Gson)7 Test (org.junit.Test)6 EncoderException (org.opencastproject.composer.api.EncoderException)6 Track (org.opencastproject.mediapackage.Track)5 Response (javax.ws.rs.core.Response)4 JobImpl (org.opencastproject.job.api.JobImpl)3 NotFoundException (org.opencastproject.util.NotFoundException)3 IOException (java.io.IOException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Dimension (org.opencastproject.composer.layout.Dimension)2 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)2