use of org.opencastproject.job.api.Job in project opencast by opencast.
the class AwsS3DistributionRestService method distribute.
@POST
@Path("/")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "distribute", description = "Distribute a media package element to this distribution channel", returnDescription = "The job that can be used to track the distribution", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The mediapackage", type = Type.TEXT), @RestParameter(name = "channelId", isRequired = true, description = "The publication channel ID", type = Type.TEXT), @RestParameter(name = "elementId", isRequired = true, description = "The element to distribute", type = Type.STRING), @RestParameter(name = "checkAvailability", isRequired = false, description = "If the service should try to access the distributed element", type = Type.BOOLEAN) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the distribution job") })
public Response distribute(@FormParam("mediapackage") String mediaPackageXml, @FormParam("channelId") String channelId, @FormParam("elementId") String elementId, @DefaultValue("true") @FormParam("checkAvailability") boolean checkAvailability) throws Exception {
Job job = null;
try {
Gson gson = new Gson();
Set<String> setElementIds = gson.fromJson(elementId, new TypeToken<Set<String>>() {
}.getType());
MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
job = service.distribute(channelId, mediapackage, setElementIds, checkAvailability);
} catch (IllegalArgumentException e) {
logger.debug("Unable to distribute element: {}", e.getMessage());
return status(Status.BAD_REQUEST).build();
} catch (Exception e) {
logger.warn("Unable to distribute media package {}, element {} to aws s3 channel: {}", mediaPackageXml, elementId, e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
return Response.ok(new JaxbJob(job)).build();
}
use of org.opencastproject.job.api.Job in project opencast by opencast.
the class DownloadDistributionServiceRemoteImpl method distribute.
@Override
public Job distribute(String channelId, final MediaPackage mediaPackage, Set<String> elementIds, boolean checkAvailability, boolean preserveReference) throws DistributionException {
logger.info(format("Distributing %s elements to %s@%s", elementIds.size(), channelId, distributionChannel));
final HttpPost req = post(param(PARAM_CHANNEL_ID, channelId), param(PARAM_MEDIAPACKAGE, MediaPackageParser.getAsXml(mediaPackage)), param(PARAM_ELEMENT_ID, gson.toJson(elementIds)), param(PARAM_CHECK_AVAILABILITY, Boolean.toString(checkAvailability)), param(PARAM_PRESERVE_REFERENCE, Boolean.toString(preserveReference)));
for (Job job : join(runRequest(req, jobFromHttpResponse))) {
return job;
}
throw new DistributionException(format("Unable to distribute '%s' elements of " + "mediapackage '%s' using a remote destribution service proxy", elementIds.size(), mediaPackage.getIdentifier().toString()));
}
use of org.opencastproject.job.api.Job in project opencast by opencast.
the class DownloadDistributionServiceRemoteImpl method retract.
@Override
public Job retract(String channelId, MediaPackage mediaPackage, Set<String> elementIds) throws DistributionException {
logger.info(format("Retracting %s elements from %s@%s", elementIds.size(), channelId, distributionChannel));
final HttpPost req = post("/retract", param(PARAM_MEDIAPACKAGE, MediaPackageParser.getAsXml(mediaPackage)), param(PARAM_ELEMENT_ID, gson.toJson(elementIds)), param(PARAM_CHANNEL_ID, channelId));
for (Job job : join(runRequest(req, jobFromHttpResponse))) {
return job;
}
throw new DistributionException(format("Unable to retract '%s' elements of " + "mediapackage '%s' using a remote destribution service proxy", elementIds.size(), mediaPackage.getIdentifier().toString()));
}
use of org.opencastproject.job.api.Job in project opencast by opencast.
the class DownloadDistributionRestService method distribute.
@POST
@Path("/")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "distribute", description = "Distribute a media package element to this distribution channel", returnDescription = "The job that can be used to track the distribution", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The mediapackage", type = Type.TEXT), @RestParameter(name = "channelId", isRequired = true, description = "The publication channel ID", type = Type.TEXT), @RestParameter(name = "elementId", isRequired = true, description = "The element to distribute. The Id or multiple Ids as JSON Array ( ['IdOne','IdTwo'] )", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the distribution job") })
public Response distribute(@FormParam("mediapackage") String mediaPackageXml, @FormParam("elementId") String elementId, @FormParam("channelId") String channelId, @DefaultValue("true") @FormParam("checkAvailability") boolean checkAvailability, @DefaultValue("false") @FormParam("preserveReference") boolean preserveReference) throws Exception {
try {
Gson gson = new Gson();
Set<String> setElementIds = gson.fromJson(elementId, new TypeToken<Set<String>>() {
}.getType());
final MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
final Job job = service.distribute(channelId, mediapackage, setElementIds, checkAvailability, preserveReference);
return ok(new JaxbJob(job));
} catch (IllegalArgumentException e) {
logger.debug("Unable to distribute element: {}", e.getMessage());
return status(Status.BAD_REQUEST).build();
} catch (Exception e) {
logger.warn("Error distributing element", e);
return serverError();
}
}
use of org.opencastproject.job.api.Job in project opencast by opencast.
the class RetractYouTubeWorkflowOperationHandler method start.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(WorkflowInstance, JobContext)
*/
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
MediaPackage mediaPackage = workflowInstance.getMediaPackage();
try {
logger.info("Retracting media package {} from youtube publication channel", mediaPackage);
// Wait for youtube retraction to finish
Job retractJob = publicationService.retract(mediaPackage);
if (!waitForStatus(retractJob).isSuccess())
throw new WorkflowOperationException("The youtube retract job did not complete successfully");
logger.debug("Retraction from youtube operation complete");
// Remove the retracted elements from the mediapackage
Job job = serviceRegistry.getJob(retractJob.getId());
if (job.getPayload() != null) {
logger.info("Removing youtube publication element from media package {}", mediaPackage);
Publication retractedElement = (Publication) MediaPackageElementParser.getFromXml(job.getPayload());
mediaPackage.remove(retractedElement);
logger.debug("Remove youtube publication element '{}' complete", retractedElement);
} else {
logger.info("No youtube publication found to retract in mediapackage {}!", mediaPackage);
return createResult(mediaPackage, Action.CONTINUE);
}
return createResult(mediaPackage, Action.CONTINUE);
} catch (Throwable t) {
throw new WorkflowOperationException(t);
}
}
Aggregations