Search in sources :

Example 31 with JaxbJob

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

the class JobTest method testMarshallingWithXmlPayload.

@Test
public void testMarshallingWithXmlPayload() throws Exception {
    final String payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<random xmlns:ns2=\"http://mediapackage.opencastproject.org\" xmlns:ns3=\"http://job.opencastproject.org/\">something</random>";
    Job job = new JobImpl();
    job.setPayload(payload);
    String marshalledJob = JobParser.toXml(new JaxbJob(job));
    Job unmarshalledJob = JobParser.parseJob(marshalledJob);
    assertEquals("xml 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 32 with JaxbJob

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

the class SilenceDetectionServiceEndpoint method detect.

@POST
@Path("/detect")
@Produces({ MediaType.APPLICATION_XML })
@RestQuery(name = "detect", description = "Create silence detection job.", returnDescription = "Silence detection job.", restParameters = { @RestParameter(name = "track", type = RestParameter.Type.TEXT, description = "Track where to run silence detection.", isRequired = true), @RestParameter(name = "referenceTracks", type = RestParameter.Type.TEXT, description = "Tracks referenced by resulting smil (as sources).", isRequired = false) }, reponses = { @RestResponse(description = "Silence detection job created successfully.", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Create silence detection job failed.", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) })
public Response detect(@FormParam("track") String trackXml, @FormParam("referenceTracks") String referenceTracksXml) {
    try {
        Track track = (Track) MediaPackageElementParser.getFromXml(trackXml);
        Job job = null;
        if (referenceTracksXml != null) {
            List<Track> referenceTracks = null;
            referenceTracks = (List<Track>) MediaPackageElementParser.getArrayFromXml(referenceTracksXml);
            job = silenceDetectionService.detect(track, referenceTracks.toArray(new Track[referenceTracks.size()]));
        } else {
            job = silenceDetectionService.detect(track);
        }
        return Response.ok(new JaxbJob(job)).build();
    } catch (Exception ex) {
        return Response.serverError().entity(ex.getMessage()).build();
    }
}
Also used : JaxbJob(org.opencastproject.job.api.JaxbJob) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Track(org.opencastproject.mediapackage.Track) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 33 with JaxbJob

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

the class ServiceRegistryEndpoint method createJob.

@POST
@Path("job")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "createjob", description = "Creates a new job.", returnDescription = "An XML representation of the job.", restParameters = { @RestParameter(name = "jobType", isRequired = true, type = Type.STRING, description = "The job type identifier"), @RestParameter(name = "host", isRequired = true, type = Type.STRING, description = "The creating host, including the http(s) protocol"), @RestParameter(name = "operation", isRequired = true, type = Type.STRING, description = "The operation this job should execute"), @RestParameter(name = "payload", isRequired = false, type = Type.TEXT, description = "The job type identifier"), @RestParameter(name = "start", isRequired = false, type = Type.BOOLEAN, description = "Whether the job should be queued for dispatch and execution"), @RestParameter(name = "jobLoad", isRequired = false, type = Type.STRING, description = "The load this job will incur on the system"), @RestParameter(name = "arg", isRequired = false, type = Type.TEXT, description = "An argument for the operation"), @RestParameter(name = "arg", isRequired = false, type = Type.TEXT, description = "An argument for the operation"), @RestParameter(name = "arg", isRequired = false, type = Type.TEXT, description = "An argument for the operation"), @RestParameter(name = "arg", isRequired = false, type = Type.TEXT, description = "An argument for the operation"), @RestParameter(name = "arg", isRequired = false, type = Type.TEXT, description = "An argument for the operation") }, reponses = { @RestResponse(responseCode = SC_CREATED, description = "Job created."), @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required parameters were not supplied, bad request.") })
public Response createJob(@Context HttpServletRequest request) {
    String[] argArray = request.getParameterValues("arg");
    List<String> arguments = null;
    if (argArray != null && argArray.length > 0) {
        arguments = Arrays.asList(argArray);
    }
    String jobType = request.getParameter("jobType");
    String operation = request.getParameter("operation");
    String host = request.getParameter("host");
    String payload = request.getParameter("payload");
    boolean start = StringUtils.isBlank(request.getParameter("start")) || Boolean.TRUE.toString().equalsIgnoreCase(request.getParameter("start"));
    try {
        Job job = null;
        if (StringUtils.isNotBlank(request.getParameter("jobLoad"))) {
            Float jobLoad = Float.parseFloat(request.getParameter("jobLoad"));
            job = ((ServiceRegistryJpaImpl) serviceRegistry).createJob(host, jobType, operation, arguments, payload, start, serviceRegistry.getCurrentJob(), jobLoad);
        } else {
            job = ((ServiceRegistryJpaImpl) serviceRegistry).createJob(host, jobType, operation, arguments, payload, start, serviceRegistry.getCurrentJob());
        }
        return Response.created(job.getUri()).entity(new JaxbJob(job)).build();
    } catch (IllegalArgumentException e) {
        throw new WebApplicationException(Status.BAD_REQUEST);
    } catch (Exception e) {
        throw new WebApplicationException(e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) JaxbJob(org.opencastproject.job.api.JaxbJob) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) WebApplicationException(javax.ws.rs.WebApplicationException) NotFoundException(org.opencastproject.util.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 34 with JaxbJob

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

the class WaveformServiceEndpoint method createWaveformImage.

@POST
@Path("/create")
@Produces({ MediaType.APPLICATION_XML })
@RestQuery(name = "create", description = "Create a waveform image from the given track", returnDescription = "Media package attachment for the generated waveform.", restParameters = { @RestParameter(name = "track", type = RestParameter.Type.TEXT, description = "Track with at least one audio channel.", isRequired = true) }, reponses = { @RestResponse(description = "Waveform generation job successfully created.", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "The given track can't be parsed.", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "Internal server error.", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) })
public Response createWaveformImage(@FormParam("track") String track) {
    try {
        MediaPackageElement sourceTrack = MediaPackageElementParser.getFromXml(track);
        if (!Track.TYPE.equals(sourceTrack.getElementType()))
            return Response.status(Response.Status.BAD_REQUEST).entity("Track element must be of type track").build();
        Job job = waveformService.createWaveformImage((Track) sourceTrack);
        return Response.ok().entity(new JaxbJob(job)).build();
    } catch (WaveformServiceException ex) {
        logger.error("Creating waveform job for track {} failed: {}", track, ExceptionUtils.getStackTrace(ex));
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    } catch (MediaPackageException ex) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Track element parsing failure").build();
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) WaveformServiceException(org.opencastproject.waveform.api.WaveformServiceException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) JaxbJob(org.opencastproject.job.api.JaxbJob) 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 35 with JaxbJob

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

the class VideoEditorServiceRemote method processSmil.

@Override
public List<Job> processSmil(Smil smil) throws ProcessFailedException {
    HttpPost post = new HttpPost("/process-smil");
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    try {
        params.add(new BasicNameValuePair("smil", smil.toXML()));
        post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
    } catch (Exception e) {
        throw new ProcessFailedException("Unable to assemble a remote videoeditor request for smil " + smil.getId());
    }
    HttpResponse response = null;
    try {
        response = getResponse(post);
        if (response != null) {
            String entity = EntityUtils.toString(response.getEntity());
            if (StringUtils.isNotEmpty(entity)) {
                List<Job> jobs = new LinkedList<Job>();
                for (JaxbJob job : JobParser.parseJobList(entity).getJobs()) {
                    jobs.add(job.toJob());
                }
                logger.info("Start proccessing smil '{}' on remote videoeditor service", smil.getId());
                return jobs;
            }
        }
    } catch (Exception e) {
        throw new ProcessFailedException("Unable to proccess smil " + smil.getId() + " using a remote videoeditor service", e);
    } finally {
        closeConnection(response);
    }
    throw new ProcessFailedException("Unable to proccess smil " + smil.getId() + " using a remote videoeditor service.");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) JaxbJob(org.opencastproject.job.api.JaxbJob) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) ProcessFailedException(org.opencastproject.videoeditor.api.ProcessFailedException) LinkedList(java.util.LinkedList) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ProcessFailedException(org.opencastproject.videoeditor.api.ProcessFailedException) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job)

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