Search in sources :

Example 56 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class SeriesServiceRemoteImpl method getSeriesProperty.

@Override
public String getSeriesProperty(String seriesID, String propertyName) throws SeriesException, NotFoundException, UnauthorizedException {
    HttpGet get = new HttpGet(seriesID + "/property/" + propertyName + ".json");
    HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
    try {
        if (response != null) {
            if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
                throw new NotFoundException("Series " + seriesID + " not found in remote series index!");
            } else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
                throw new UnauthorizedException("Not authorized to get series " + seriesID);
            } else {
                logger.debug("Successfully received series {} property {} from the remote series index", seriesID, propertyName);
                StringWriter writer = new StringWriter();
                IOUtils.copy(response.getEntity().getContent(), writer, "UTF-8");
                return writer.toString();
            }
        }
    } catch (UnauthorizedException e) {
        throw e;
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        throw new SeriesException("Unable to parse series from remote series index: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SeriesException("Unable to get series from remote series index");
}
Also used : StringWriter(java.io.StringWriter) HttpGet(org.apache.http.client.methods.HttpGet) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) SeriesException(org.opencastproject.series.api.SeriesException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 57 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class SeriesServiceRemoteImpl method getSeriesAccessControl.

@Override
public AccessControlList getSeriesAccessControl(String seriesID) throws NotFoundException, SeriesException {
    HttpGet get = new HttpGet(seriesID + "/acl.xml");
    HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND);
    try {
        if (response != null) {
            if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
                throw new NotFoundException("Series ACL " + seriesID + " not found on remote series index!");
            } else {
                AccessControlList acl = AccessControlParser.parseAcl(response.getEntity().getContent());
                logger.info("Successfully get series ACL {} from the remote series index", seriesID);
                return acl;
            }
        }
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        throw new SeriesException("Unable to parse series ACL form remote series index: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SeriesException("Unable to get series ACL from remote series index");
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) SeriesException(org.opencastproject.series.api.SeriesException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 58 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class AbstractIncidentService method getIncidentsOfJob.

@Override
public IncidentTree getIncidentsOfJob(long jobId, boolean cascade) throws NotFoundException, IncidentServiceException {
    List<Incident> incidents = getIncidentsOfJob(jobId);
    List<IncidentTree> childIncidents = new ArrayList<IncidentTree>();
    try {
        Job job = getServiceRegistry().getJob(jobId);
        if (cascade && !"START_WORKFLOW".equals(job.getOperation())) {
            childIncidents = getChildIncidents(jobId);
        } else if (cascade && "START_WORKFLOW".equals(job.getOperation())) {
            for (WorkflowOperationInstance operation : getWorkflowService().getWorkflowById(jobId).getOperations()) {
                if (operation.getState().equals(OperationState.INSTANTIATED))
                    continue;
                IncidentTree operationResult = getIncidentsOfJob(operation.getId(), true);
                if (hasIncidents(Collections.list(operationResult)))
                    childIncidents.add(operationResult);
            }
        }
        return new IncidentTreeImpl(incidents, childIncidents);
    } catch (NotFoundException ignore) {
        // Workflow deleted
        return new IncidentTreeImpl(incidents, childIncidents);
    } catch (Exception e) {
        logger.error("Error loading child jobs of {}: {}", jobId);
        throw new IncidentServiceException(e);
    }
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) IncidentTreeImpl(org.opencastproject.job.api.IncidentTreeImpl) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) ArrayList(java.util.ArrayList) NotFoundException(org.opencastproject.util.NotFoundException) Incident(org.opencastproject.job.api.Incident) Job(org.opencastproject.job.api.Job) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) NotFoundException(org.opencastproject.util.NotFoundException) IncidentTree(org.opencastproject.job.api.IncidentTree)

Example 59 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class ServiceRegistryJpaImpl method removeJobs.

@Override
public void removeJobs(List<Long> jobIds) throws NotFoundException, ServiceRegistryException {
    for (long jobId : jobIds) {
        if (jobId < 1)
            throw new NotFoundException("Job ID must be greater than zero (0)");
    }
    logger.debug("Start deleting jobs with IDs '{}'", jobIds);
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        for (long jobId : jobIds) {
            JpaJob job = em.find(JpaJob.class, jobId);
            if (job == null) {
                logger.error("Job with Id {} cannot be deleted: Not found.", jobId);
                tx.rollback();
                throw new NotFoundException("Job with ID '" + jobId + "' not found");
            }
            deleteChildJobs(em, tx, jobId);
            em.remove(job);
        }
        tx.commit();
        logger.debug("Jobs with IDs '{}' deleted", jobIds);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) NotFoundException(org.opencastproject.util.NotFoundException) JpaJob(org.opencastproject.job.jpa.JpaJob)

Example 60 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class ServiceRegistryJpaImpl method createJob.

/**
 * Creates a job on a remote host.
 */
public Job createJob(String host, String serviceType, String operation, List<String> arguments, String payload, boolean dispatchable, Job parentJob, float jobLoad) throws ServiceRegistryException {
    if (StringUtils.isBlank(host)) {
        throw new IllegalArgumentException("Host can't be null");
    }
    if (StringUtils.isBlank(serviceType)) {
        throw new IllegalArgumentException("Service type can't be null");
    }
    if (StringUtils.isBlank(operation)) {
        throw new IllegalArgumentException("Operation can't be null");
    }
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        ServiceRegistrationJpaImpl creatingService = getServiceRegistration(em, serviceType, host);
        if (creatingService == null) {
            throw new ServiceRegistryException("No service registration exists for type '" + serviceType + "' on host '" + host + "'");
        }
        if (creatingService.getHostRegistration().isMaintenanceMode()) {
            logger.warn("Creating a job from {}, which is currently in maintenance mode.", creatingService.getHost());
        } else if (!creatingService.getHostRegistration().isActive()) {
            logger.warn("Creating a job from {}, which is currently inactive.", creatingService.getHost());
        }
        User currentUser = securityService.getUser();
        Organization currentOrganization = securityService.getOrganization();
        JpaJob jpaJob = new JpaJob(currentUser, currentOrganization, creatingService, operation, arguments, payload, dispatchable, jobLoad);
        // Bind the given parent job to the new job
        if (parentJob != null) {
            // Get the JPA instance of the parent job
            JpaJob jpaParentJob;
            try {
                jpaParentJob = getJpaJob(parentJob.getId());
            } catch (NotFoundException e) {
                logger.error("{} not found in the persistence context", parentJob);
                throw new ServiceRegistryException(e);
            }
            jpaJob.setParentJob(jpaParentJob);
            // Get the JPA instance of the root job
            JpaJob jpaRootJob = jpaParentJob;
            if (parentJob.getRootJobId() != null) {
                try {
                    jpaRootJob = getJpaJob(parentJob.getRootJobId());
                } catch (NotFoundException e) {
                    logger.error("job with id {} not found in the persistence context", parentJob.getRootJobId());
                    throw new ServiceRegistryException(e);
                }
            }
            jpaJob.setRootJob(jpaRootJob);
        }
        // if this job is not dispatchable, it must be handled by the host that has created it
        if (dispatchable) {
            jpaJob.setStatus(Status.QUEUED);
        } else {
            jpaJob.setProcessorServiceRegistration(creatingService);
        }
        em.persist(jpaJob);
        tx.commit();
        setJobUri(jpaJob);
        Job job = jpaJob.toJob();
        return job;
    } catch (RollbackException e) {
        if (tx != null && tx.isActive()) {
            tx.rollback();
        }
        throw e;
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) NotFoundException(org.opencastproject.util.NotFoundException) ServiceRegistrationJpaImpl(org.opencastproject.serviceregistry.impl.jpa.ServiceRegistrationJpaImpl) JpaJob(org.opencastproject.job.jpa.JpaJob) JpaJob.fnToJob(org.opencastproject.job.jpa.JpaJob.fnToJob) Job(org.opencastproject.job.api.Job) JpaJob(org.opencastproject.job.jpa.JpaJob) RollbackException(javax.persistence.RollbackException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Aggregations

NotFoundException (org.opencastproject.util.NotFoundException)382 IOException (java.io.IOException)137 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)130 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)79 MediaPackage (org.opencastproject.mediapackage.MediaPackage)69 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)67 EntityManager (javax.persistence.EntityManager)55 SeriesException (org.opencastproject.series.api.SeriesException)53 Path (javax.ws.rs.Path)52 WebApplicationException (javax.ws.rs.WebApplicationException)52 RestQuery (org.opencastproject.util.doc.rest.RestQuery)51 ConfigurationException (org.osgi.service.cm.ConfigurationException)51 URI (java.net.URI)50 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)50 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)49 Date (java.util.Date)48 Test (org.junit.Test)47 File (java.io.File)46 HttpResponse (org.apache.http.HttpResponse)46 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)46