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()));
}
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();
}
}
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);
}
}
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();
}
}
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.");
}
Aggregations