use of org.opencastproject.job.api.Job in project opencast by opencast.
the class ServiceRegistryInMemoryImpl method removeParentlessJobs.
@Override
public void removeParentlessJobs(int lifetime) throws ServiceRegistryException {
synchronized (jobs) {
for (String serializedJob : jobs.values()) {
Job job = null;
try {
job = JobParser.parseJob(serializedJob);
} catch (IOException e) {
throw new IllegalStateException("Error unmarshaling job", e);
}
Long parentJobId = job.getParentJobId();
if (parentJobId == null | parentJobId < 1)
jobs.remove(job.getId());
}
}
}
use of org.opencastproject.job.api.Job in project opencast by opencast.
the class ServiceRegistryInMemoryImpl method updateJob.
/**
* {@inheritDoc}
*
* @see org.opencastproject.serviceregistry.api.ServiceRegistry#updateJob(org.opencastproject.job.api.Job)
*/
@Override
public Job updateJob(Job job) throws NotFoundException, ServiceRegistryException {
if (job == null)
throw new IllegalArgumentException("Job cannot be null");
Job updatedJob = null;
synchronized (jobs) {
try {
updatedJob = updateInternal(job);
jobs.put(updatedJob.getId(), JobParser.toXml(new JaxbJob(updatedJob)));
} catch (IOException e) {
throw new IllegalStateException("Error serializing job", e);
}
}
return updatedJob;
}
use of org.opencastproject.job.api.Job in project opencast by opencast.
the class ServiceRegistryInMemoryImpl method dispatchJob.
/**
* Dispatches the job to the least loaded service or throws a <code>ServiceUnavailableException</code> if there is no
* such service.
*
* @param job
* the job to dispatch
* @return whether the job was dispatched
* @throws ServiceUnavailableException
* if no service is available to dispatch the job
* @throws ServiceRegistryException
* if the service registrations are unavailable or dispatching of the job fails
*/
protected boolean dispatchJob(Job job) throws ServiceUnavailableException, ServiceRegistryException, UndispatchableJobException {
List<ServiceRegistration> registrations = getServiceRegistrationsByLoad(job.getJobType());
if (registrations.size() == 0)
throw new ServiceUnavailableException("No service is available to handle jobs of type '" + job.getJobType() + "'");
job.setStatus(Status.DISPATCHING);
try {
job = updateJob(job);
} catch (NotFoundException e) {
throw new ServiceRegistryException("Job not found!", e);
}
for (ServiceRegistration registration : registrations) {
if (registration.isJobProducer() && !registration.isInMaintenanceMode()) {
ServiceRegistrationInMemoryImpl inMemoryRegistration = (ServiceRegistrationInMemoryImpl) registration;
JobProducer service = inMemoryRegistration.getService();
// Add the job to the list of jobs so that it gets counted in the load.
// This is the same way that the JPA impl does it
Set<Job> jobs = jobHosts.get(inMemoryRegistration);
if (jobs == null) {
jobs = new LinkedHashSet<Job>();
}
jobs.add(job);
jobHosts.put(inMemoryRegistration, jobs);
if (!service.isReadyToAcceptJobs(job.getOperation())) {
jobs.remove(job);
jobHosts.put(inMemoryRegistration, jobs);
continue;
}
if (!service.isReadyToAccept(job)) {
jobs.remove(job);
jobHosts.put(inMemoryRegistration, jobs);
continue;
}
try {
job = updateJob(job);
} catch (NotFoundException e) {
jobs.remove(job);
jobHosts.put(inMemoryRegistration, jobs);
throw new ServiceRegistryException("Job not found!", e);
}
service.acceptJob(job);
return true;
} else if (!registration.isJobProducer()) {
logger.warn("This implementation of the service registry doesn't support dispatching to remote services");
// TODO: Add remote dispatching
} else {
logger.warn("Service " + registration + " is in maintenance mode");
}
}
return false;
}
use of org.opencastproject.job.api.Job in project opencast by opencast.
the class StreamingDistributionServiceRemoteImpl 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_IDS, 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 StreamingDistributionServiceRemoteImpl method distribute.
@Override
public Job distribute(String channelId, final MediaPackage mediaPackage, Set<String> elementIds) throws DistributionException, MediaPackageException {
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_IDS, gson.toJson(elementIds)));
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()));
}
Aggregations