use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class IngestServiceImpl method addPartialTrack.
@Override
public MediaPackage addPartialTrack(URI uri, MediaPackageElementFlavor flavor, long startTime, MediaPackage mediaPackage) throws IOException, IngestException {
Job job = null;
try {
job = serviceRegistry.createJob(JOB_TYPE, INGEST_TRACK_FROM_URI, Arrays.asList(uri.toString(), flavor == null ? null : flavor.toString(), MediaPackageParser.getAsXml(mediaPackage)), null, false);
job.setStatus(Status.RUNNING);
job = serviceRegistry.updateJob(job);
String elementId = UUID.randomUUID().toString();
logger.info("Start adding partial track {} from URL {} on mediapackage {}", elementId, uri, mediaPackage);
URI newUrl = addContentToRepo(mediaPackage, elementId, uri);
MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Track, flavor);
job.setStatus(Job.Status.FINISHED);
// store startTime
partialTrackStartTimes.put(elementId, startTime);
logger.debug("Added start time {} for track {}", startTime, elementId);
logger.info("Successful added partial track {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
return mp;
} catch (ServiceRegistryException e) {
throw new IngestException(e);
} catch (NotFoundException e) {
throw new IngestException("Unable to update ingest job", e);
} finally {
finallyUpdateJob(job);
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class IngestServiceImpl method addTrack.
/**
* {@inheritDoc}
*
* @see org.opencastproject.ingest.api.IngestService#addTrack(java.io.InputStream, java.lang.String,
* org.opencastproject.mediapackage.MediaPackageElementFlavor, org.opencastproject.mediapackage.MediaPackage)
*/
@Override
public MediaPackage addTrack(InputStream in, String fileName, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage) throws IOException, IngestException {
Job job = null;
try {
job = serviceRegistry.createJob(JOB_TYPE, INGEST_TRACK, null, null, false, ingestFileJobLoad);
job.setStatus(Status.RUNNING);
job = serviceRegistry.updateJob(job);
String elementId = UUID.randomUUID().toString();
logger.info("Start adding track {} from input stream on mediapackage {}", elementId, mediaPackage);
URI newUrl = addContentToRepo(mediaPackage, elementId, fileName, in);
MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Track, flavor);
if (tags != null && tags.length > 0) {
MediaPackageElement trackElement = mp.getTrack(elementId);
for (String tag : tags) {
logger.info("Adding Tag: " + tag + " to Element: " + elementId);
trackElement.addTag(tag);
}
}
job.setStatus(Job.Status.FINISHED);
logger.info("Successful added track {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
return mp;
} catch (IOException e) {
throw e;
} catch (ServiceRegistryException e) {
throw new IngestException(e);
} catch (NotFoundException e) {
throw new IngestException("Unable to update ingest job", e);
} finally {
finallyUpdateJob(job);
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class JobEndpoint method getTasksAsJSON.
/**
* Returns the single task with the given Id as JSON Object
*
* @param id
* @return The job as JSON Object
* @throws JobEndpointException
* @throws NotFoundException
*/
public JObject getTasksAsJSON(long id) throws JobEndpointException, NotFoundException {
WorkflowInstance instance = getWorkflowById(id);
// Retrieve submission date with the workflow instance main job
Date created;
long duration = 0;
try {
Job job = serviceRegistry.getJob(id);
created = job.getDateCreated();
Date completed = job.getDateCompleted();
if (completed == null)
completed = new Date();
duration = (completed.getTime() - created.getTime());
} catch (ServiceRegistryException e) {
throw new JobEndpointException(String.format("Error when retrieving job %s from the service registry: %s", id, e), e.getCause());
}
MediaPackage mp = instance.getMediaPackage();
List<Field> fields = new ArrayList<>();
for (String key : instance.getConfigurationKeys()) {
fields.add(f(key, v(instance.getConfiguration(key), Jsons.BLANK)));
}
return obj(f("start", v(created != null ? toUTC(created.getTime()) : "", Jsons.BLANK)), f("state", v(instance.getState(), Jsons.BLANK)), f("description", v(instance.getDescription(), Jsons.BLANK)), f("duration", v(duration, Jsons.BLANK)), f("id", v(instance.getId(), Jsons.BLANK)), f("workflow", v(instance.getTitle(), Jsons.BLANK)), f("workflowId", v(instance.getTemplate(), Jsons.BLANK)), f("title", v(mp.getTitle(), Jsons.BLANK)), f("series", v(mp.getSeries(), Jsons.BLANK)), f("series_title", v(mp.getSeriesTitle(), Jsons.BLANK)), f("license", v(mp.getLicense(), Jsons.BLANK)), f("configuration", obj(fields)));
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class JobEndpoint method getJobs.
@GET
@Path("jobs.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(description = "Returns the list of active jobs", name = "jobs", restParameters = { @RestParameter(name = "limit", description = "The maximum number of items to return per page", isRequired = false, type = RestParameter.Type.INTEGER), @RestParameter(name = "offset", description = "The offset", isRequired = false, type = RestParameter.Type.INTEGER), @RestParameter(name = "filter", description = "Filter results by hostname, status or free text query", isRequired = false, type = RestParameter.Type.STRING), @RestParameter(name = "sort", description = "The sort order. May include any of the following: CREATOR, OPERATION, PROCESSINGHOST, STATUS, STARTED, SUBMITTED or TYPE. " + "The suffix must be :ASC for ascending or :DESC for descending sort order (e.g. OPERATION:DESC)", isRequired = false, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns the list of active jobs from Opencast", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "The list of jobs as JSON")
public Response getJobs(@QueryParam("limit") final int limit, @QueryParam("offset") final int offset, @QueryParam("filter") final String filter, @QueryParam("sort") final String sort) {
JobsListQuery query = new JobsListQuery();
EndpointUtil.addRequestFiltersToQuery(filter, query);
query.setLimit(limit);
query.setOffset(offset);
String fHostname = null;
if (query.getHostname().isSome())
fHostname = StringUtils.trimToNull(query.getHostname().get());
String fStatus = null;
if (query.getStatus().isSome())
fStatus = StringUtils.trimToNull(query.getStatus().get());
String fFreeText = null;
if (query.getFreeText().isSome())
fFreeText = StringUtils.trimToNull(query.getFreeText().get());
List<Job> jobs = new ArrayList<>();
try {
for (Job job : serviceRegistry.getActiveJobs()) {
// filter workflow jobs
if (StringUtils.equals(WorkflowService.JOB_TYPE, job.getJobType()) && StringUtils.equals("START_WORKFLOW", job.getOperation()))
continue;
// filter by hostname
if (fHostname != null && !StringUtils.equalsIgnoreCase(job.getProcessingHost(), fHostname))
continue;
// filter by status
if (fStatus != null && !StringUtils.equalsIgnoreCase(job.getStatus().toString(), fStatus))
continue;
// fitler by user free text
if (fFreeText != null && !StringUtils.equalsIgnoreCase(job.getProcessingHost(), fFreeText) && !StringUtils.equalsIgnoreCase(job.getJobType(), fFreeText) && !StringUtils.equalsIgnoreCase(job.getOperation(), fFreeText) && !StringUtils.equalsIgnoreCase(job.getCreator(), fFreeText) && !StringUtils.equalsIgnoreCase(job.getStatus().toString(), fFreeText) && !StringUtils.equalsIgnoreCase(Long.toString(job.getId()), fFreeText) && (job.getRootJobId() != null && !StringUtils.equalsIgnoreCase(Long.toString(job.getRootJobId()), fFreeText)))
continue;
jobs.add(job);
}
} catch (ServiceRegistryException ex) {
logger.error("Failed to retrieve jobs list from service registry.", ex);
return RestUtil.R.serverError();
}
JobSort sortKey = JobSort.SUBMITTED;
boolean ascending = true;
if (StringUtils.isNotBlank(sort)) {
try {
SortCriterion sortCriterion = RestUtils.parseSortQueryParameter(sort).iterator().next();
sortKey = JobSort.valueOf(sortCriterion.getFieldName().toUpperCase());
ascending = SearchQuery.Order.Ascending == sortCriterion.getOrder() || SearchQuery.Order.None == sortCriterion.getOrder();
} catch (WebApplicationException ex) {
logger.warn("Failed to parse sort criterion \"{}\", invalid format.", sort);
} catch (IllegalArgumentException ex) {
logger.warn("Can not apply sort criterion \"{}\", no field with this name.", sort);
}
}
JobComparator comparator = new JobComparator(sortKey, ascending);
Collections.sort(jobs, comparator);
List<JValue> json = getJobsAsJSON(new SmartIterator(query.getLimit().getOrElse(0), query.getOffset().getOrElse(0)).applyLimitAndOffset(jobs));
return RestUtils.okJsonList(json, offset, limit, jobs.size());
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class StreamingDistributionServiceImpl method distribute.
@Override
public Job distribute(String channelId, MediaPackage mediapackage, Set<String> elementIds) throws DistributionException, MediaPackageException {
notNull(mediapackage, "mediapackage");
notNull(elementIds, "elementIds");
notNull(channelId, "channelId");
try {
return serviceRegistry.createJob(JOB_TYPE, Operation.Distribute.toString(), Arrays.asList(channelId, MediaPackageParser.getAsXml(mediapackage), gson.toJson(elementIds)), distributeJobLoad);
} catch (ServiceRegistryException e) {
throw new DistributionException("Unable to create a job", e);
}
}
Aggregations