use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class TimelinePreviewsServiceImpl method process.
/**
* {@inheritDoc}
*
* @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
*/
@Override
protected String process(Job job) throws Exception {
Operation op = null;
String operation = job.getOperation();
List<String> arguments = job.getArguments();
try {
op = Operation.valueOf(operation);
switch(op) {
case TimelinePreview:
Track track = (Track) MediaPackageElementParser.getFromXml(arguments.get(0));
int imageCount = Integer.parseInt(arguments.get(1));
Attachment timelinePreviewsMpe = generatePreviewImages(job, track, imageCount);
return MediaPackageElementParser.getAsXml(timelinePreviewsMpe);
default:
throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
}
} catch (IllegalArgumentException e) {
throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
} catch (IndexOutOfBoundsException e) {
throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
} catch (Exception e) {
throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class AbstractJobProducer method isReadyToAccept.
/**
* {@inheritDoc}
*
* @see org.opencastproject.job.api.JobProducer#isReadyToAccept(org.opencastproject.job.api.Job)
*/
@Override
public boolean isReadyToAccept(Job job) throws ServiceRegistryException, UndispatchableJobException {
if (!jobType.equals(job.getJobType())) {
logger.debug("Invalid job type submitted: {}", job.getJobType());
return false;
}
NodeLoad maxload;
try {
maxload = getServiceRegistry().getMaxLoadOnNode(getServiceRegistry().getRegistryHostname());
} catch (NotFoundException e) {
throw new ServiceRegistryException(e);
}
// Note: We are not adding the job load in the next line because it is already accounted for in the load values we
// get back from the service registry.
float currentLoad = getServiceRegistry().getOwnLoad();
/* Note that this first clause looks at the *job's*, the other two look at the *node's* load
* We're assuming that if this case is true, then we're also the most powerful node in the system for this service,
* per the current job dispatching code in ServiceRegistryJpaImpl */
if (job.getJobLoad() > maxload.getLoadFactor() && acceptJobLoadsExeedingMaxLoad) {
logger.warn("Accepting job {} of type {} with load {} even though load of {} is above this node's limit of {}.", new Object[] { job.getId(), job.getJobType(), df.format(job.getJobLoad()), df.format(currentLoad), df.format(maxload.getLoadFactor()) });
logger.warn("This is a configuration issue that you should resolve in a production system!");
return true;
} else if (currentLoad > maxload.getLoadFactor()) {
logger.debug("Declining job {} of type {} with load {} because load of {} would exceed this node's limit of {}.", new Object[] { job.getId(), job.getJobType(), df.format(job.getJobLoad()), df.format(currentLoad), df.format(maxload.getLoadFactor()) });
return false;
} else {
logger.debug("Accepting job {} of type {} with load {} because load of {} is within this node's limit of {}.", new Object[] { job.getId(), job.getJobType(), df.format(job.getJobLoad()), df.format(currentLoad), df.format(maxload.getLoadFactor()) });
return true;
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class ExecuteServiceImpl method execute.
/**
* {@inheritDoc}
*
* @see org.opencastproject.execute.api.ExecuteService#execute(java.lang.String, java.lang.String,
* org.opencastproject.mediapackage.MediaPackageElement, java.lang.String,
* org.opencastproject.mediapackage.MediaPackageElement.Type, float)
* @throws IllegalArgumentException
* if the input arguments are incorrect
* @throws ExecuteException
* if an internal error occurs
*/
@Override
public Job execute(String exec, String params, MediaPackageElement inElement, String outFileName, Type expectedType, float load) throws ExecuteException, IllegalArgumentException {
logger.debug("Creating Execute Job for command: {}", exec);
if (StringUtils.isBlank(exec))
throw new IllegalArgumentException("The command to execute cannot be null");
if (StringUtils.isBlank(params))
throw new IllegalArgumentException("The command arguments cannot be null");
if (inElement == null)
throw new IllegalArgumentException("The input MediaPackage element cannot be null");
outFileName = StringUtils.trimToNull(outFileName);
if ((outFileName == null) && (expectedType != null) || (outFileName != null) && (expectedType == null))
throw new IllegalArgumentException("Expected element type and output filename cannot be null");
try {
List<String> paramList = new ArrayList<String>(5);
paramList.add(exec);
paramList.add(params);
paramList.add(MediaPackageElementParser.getAsXml(inElement));
paramList.add(outFileName);
paramList.add((expectedType == null) ? null : expectedType.toString());
return serviceRegistry.createJob(JOB_TYPE, Operation.Execute_Element.toString(), paramList, load);
} catch (ServiceRegistryException e) {
throw new ExecuteException(String.format("Unable to create a job of type '%s'", JOB_TYPE), e);
} catch (MediaPackageException e) {
throw new ExecuteException("Error serializing an element", e);
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class ExecuteServiceImpl method execute.
/**
* {@inheritDoc}
*
* @see org.opencastproject.execute.api.ExecuteService#execute(java.lang.String, java.lang.String,
* org.opencastproject.mediapackage.MediaPackage, java.lang.String,
* org.opencastproject.mediapackage.MediaPackageElement.Type, float)
*/
@Override
public Job execute(String exec, String params, MediaPackage mp, String outFileName, Type expectedType, float load) throws ExecuteException {
if (StringUtils.isBlank(exec))
throw new IllegalArgumentException("The command to execute cannot be null");
if (StringUtils.isBlank(params))
throw new IllegalArgumentException("The command arguments cannot be null");
if (mp == null)
throw new IllegalArgumentException("The input MediaPackage cannot be null");
outFileName = StringUtils.trimToNull(outFileName);
if ((outFileName == null) && (expectedType != null) || (outFileName != null) && (expectedType == null))
throw new IllegalArgumentException("Expected element type and output filename cannot be null");
try {
List<String> paramList = new ArrayList<String>(5);
paramList.add(exec);
paramList.add(params);
paramList.add(MediaPackageParser.getAsXml(mp));
paramList.add(outFileName);
paramList.add((expectedType == null) ? null : expectedType.toString());
return serviceRegistry.createJob(JOB_TYPE, Operation.Execute_Mediapackage.toString(), paramList, load);
} catch (ServiceRegistryException e) {
throw new ExecuteException(String.format("Unable to create a job of type '%s'", JOB_TYPE), e);
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class YouTubeV3PublicationServiceImpl method process.
/**
* {@inheritDoc}
*
* @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
*/
@Override
protected String process(final Job job) throws Exception {
Operation op = null;
try {
op = Operation.valueOf(job.getOperation());
List<String> arguments = job.getArguments();
MediaPackage mediapackage = MediaPackageParser.getFromXml(arguments.get(0));
switch(op) {
case Publish:
Publication publicationElement = publish(job, mediapackage, arguments.get(1));
return (publicationElement == null) ? null : MediaPackageElementParser.getAsXml(publicationElement);
case Retract:
Publication retractedElement = retract(job, mediapackage);
return (retractedElement == null) ? null : MediaPackageElementParser.getAsXml(retractedElement);
default:
throw new IllegalStateException("Don't know how to handle operation '" + job.getOperation() + "'");
}
} catch (final IllegalArgumentException e) {
throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
} catch (final IndexOutOfBoundsException e) {
throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
} catch (final Exception e) {
throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
}
}
Aggregations