Search in sources :

Example 71 with Job

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());
        }
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) IOException(java.io.IOException) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job)

Example 72 with Job

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;
}
Also used : JaxbJob(org.opencastproject.job.api.JaxbJob) IOException(java.io.IOException) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job)

Example 73 with Job

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;
}
Also used : JobProducer(org.opencastproject.job.api.JobProducer) NotFoundException(org.opencastproject.util.NotFoundException) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job)

Example 74 with Job

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()));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) DistributionException(org.opencastproject.distribution.api.DistributionException) Job(org.opencastproject.job.api.Job)

Example 75 with Job

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()));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) DistributionException(org.opencastproject.distribution.api.DistributionException) Job(org.opencastproject.job.api.Job)

Aggregations

Job (org.opencastproject.job.api.Job)282 MediaPackage (org.opencastproject.mediapackage.MediaPackage)89 ArrayList (java.util.ArrayList)82 Test (org.junit.Test)82 URI (java.net.URI)68 NotFoundException (org.opencastproject.util.NotFoundException)58 Track (org.opencastproject.mediapackage.Track)56 JaxbJob (org.opencastproject.job.api.JaxbJob)52 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)51 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)50 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)49 IOException (java.io.IOException)45 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)42 HttpPost (org.apache.http.client.methods.HttpPost)33 Path (javax.ws.rs.Path)31 Produces (javax.ws.rs.Produces)30 JobBarrier (org.opencastproject.job.api.JobBarrier)30 RestQuery (org.opencastproject.util.doc.rest.RestQuery)30 POST (javax.ws.rs.POST)29 HttpResponse (org.apache.http.HttpResponse)29