use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class AwsS3DistributionServiceImpl 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);
String channelId = arguments.get(0);
MediaPackage mediaPackage = MediaPackageParser.getFromXml(arguments.get(1));
Set<String> elementIds = gson.fromJson(arguments.get(2), new TypeToken<Set<String>>() {
}.getType());
switch(op) {
case Distribute:
Boolean checkAvailability = Boolean.parseBoolean(arguments.get(3));
MediaPackageElement[] distributedElements = distributeElements(channelId, mediaPackage, elementIds, checkAvailability);
return (distributedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(distributedElements)) : null;
case Retract:
MediaPackageElement[] retractedElements = retractElements(channelId, mediaPackage, elementIds);
return (retractedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(retractedElements)) : null;
/*
* TODO
* Commented out due to changes in the way the element IDs are passed (ie, a list rather than individual ones
* per job). This code is still useful long term, but I don't have time to write the necessary wrapper code
* around it right now.
* case Restore:
* String fileName = arguments.get(3);
* MediaPackageElement restoredElement = null;
* if (StringUtils.isNotBlank(fileName)) {
* restoredElement = restoreElement(channelId, mediaPackage, elementIds, fileName);
* } else {
* restoredElement = restoreElement(channelId, mediaPackage, elementIds, null);
* }
* return (restoredElement != null) ? MediaPackageElementParser.getAsXml(restoredElement) : null;
*/
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 DownloadDistributionServiceImpl method distribute.
@Override
public Job distribute(String channelId, MediaPackage mediapackage, Set<String> elementIds, boolean checkAvailability, boolean preserveReference) 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), Boolean.toString(checkAvailability), Boolean.toString(preserveReference)), distributeJobLoad);
} catch (ServiceRegistryException e) {
throw new DistributionException("Unable to create a job", e);
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class DownloadDistributionServiceImpl 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);
String channelId = arguments.get(0);
MediaPackage mediapackage = MediaPackageParser.getFromXml(arguments.get(1));
Set<String> elementIds = gson.fromJson(arguments.get(2), new TypeToken<Set<String>>() {
}.getType());
switch(op) {
case Distribute:
Boolean checkAvailability = Boolean.parseBoolean(arguments.get(3));
Boolean preserveReference = Boolean.parseBoolean(arguments.get(4));
MediaPackageElement[] distributedElements = distributeElements(channelId, mediapackage, elementIds, checkAvailability, preserveReference);
return (distributedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(distributedElements)) : null;
case Retract:
MediaPackageElement[] retractedElements = retractElements(channelId, mediapackage, elementIds);
return (retractedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(retractedElements)) : null;
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 StreamingDistributionServiceImpl 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);
String channelId = arguments.get(0);
MediaPackage mediapackage = MediaPackageParser.getFromXml(arguments.get(1));
Set<String> elementIds = gson.fromJson(arguments.get(2), new TypeToken<Set<String>>() {
}.getType());
switch(op) {
case Distribute:
MediaPackageElement[] distributedElements = distributeElements(channelId, mediapackage, elementIds);
return (distributedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(distributedElements)) : null;
case Retract:
MediaPackageElement[] retractedElements = retractElements(channelId, mediapackage, elementIds);
return (retractedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(retractedElements)) : null;
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 ServiceRegistryJpaImpl method setOnlineStatus.
/**
* Sets the online status of a service registration.
*
* @param serviceType
* The job type
* @param baseUrl
* the host URL
* @param online
* whether the service is online or off
* @param jobProducer
* whether this service produces jobs for long running operations
* @return the service registration
*/
protected ServiceRegistration setOnlineStatus(String serviceType, String baseUrl, String path, boolean online, Boolean jobProducer) throws ServiceRegistryException {
if (isBlank(serviceType) || isBlank(baseUrl)) {
throw new IllegalArgumentException("serviceType and baseUrl must not be blank");
}
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
HostRegistrationJpaImpl hostRegistration = fetchHostRegistration(em, baseUrl);
if (hostRegistration == null) {
throw new IllegalStateException("A service registration can not be updated when it has no associated host registration");
}
ServiceRegistrationJpaImpl registration = getServiceRegistration(em, serviceType, baseUrl);
if (registration == null) {
if (isBlank(path)) {
// we can not create a new registration without a path
throw new IllegalArgumentException("path must not be blank when registering new services");
}
if (jobProducer == null) {
// if we are not provided a value, consider it to be false
registration = new ServiceRegistrationJpaImpl(hostRegistration, serviceType, path, false);
} else {
registration = new ServiceRegistrationJpaImpl(hostRegistration, serviceType, path, jobProducer);
}
em.persist(registration);
} else {
if (StringUtils.isNotBlank(path))
registration.setPath(path);
registration.setOnline(online);
if (jobProducer != null) {
// if we are not provided a value, don't update the persistent value
registration.setJobProducer(jobProducer);
}
em.merge(registration);
}
tx.commit();
hostsStatistics.updateHost(hostRegistration);
servicesStatistics.updateService(registration);
return registration;
} catch (Exception e) {
if (tx != null && tx.isActive()) {
tx.rollback();
}
throw new ServiceRegistryException(e);
} finally {
if (em != null)
em.close();
}
}
Aggregations