Search in sources :

Example 31 with NotFoundException

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

the class WorkspaceImpl method deleteFromCollection.

@Override
public void deleteFromCollection(String collectionId, String fileName, boolean removeCollection) throws NotFoundException, IOException {
    // local delete
    final File f = workspaceFile(WorkingFileRepository.COLLECTION_PATH_PREFIX, collectionId, PathSupport.toSafeName(fileName));
    FileUtils.deleteQuietly(f);
    if (removeCollection) {
        FileSupport.delete(f.getParentFile());
    }
    // delete in WFR
    try {
        wfr.deleteFromCollection(collectionId, fileName, removeCollection);
    } catch (IllegalArgumentException e) {
        throw new NotFoundException(e);
    }
    // wait for WFR
    waitForResource(wfr.getCollectionURI(collectionId, fileName), SC_NOT_FOUND, "File %s does not disappear in WFR");
}
Also used : FileNotFoundException(java.io.FileNotFoundException) NotFoundException(org.opencastproject.util.NotFoundException) File(java.io.File)

Example 32 with NotFoundException

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

the class WorkspaceImpl method downloadIfNecessary.

/**
 * Download content of <code>uri</code> to file <code>dst</code> only if necessary, i.e. either the file does not yet
 * exist in the workspace or a newer version is available at <code>uri</code>.
 *
 * @return the file
 */
private File downloadIfNecessary(final URI src, final File dst) throws IOException, NotFoundException {
    HttpGet get = createGetRequest(src, dst);
    while (true) {
        // run the http request and handle its response
        final Either<Exception, Either<String, Option<File>>> result = trustedHttpClient.<Either<String, Option<File>>>runner(get).run(handleDownloadResponse(src, dst));
        // right: there's an expected result
        for (Either<String, Option<File>> a : result.right()) {
            // right: either a file could be found or not
            for (Option<File> ff : a.right()) {
                for (File f : ff) {
                    return f;
                }
                FileUtils.deleteQuietly(dst);
                // none
                throw new NotFoundException();
            }
            // left: file will be ready later
            for (String token : a.left()) {
                get = createGetRequest(src, dst, tuple("token", token));
                sleep(60000);
            }
        }
        // left: an exception occurred
        for (Exception e : result.left()) {
            logger.warn(format("Could not copy %s to %s: %s", src.toString(), dst.getAbsolutePath(), e.getMessage()));
            FileUtils.deleteQuietly(dst);
            throw new NotFoundException(e);
        }
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Either(org.opencastproject.util.data.Either) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(org.opencastproject.util.NotFoundException) Option(org.opencastproject.util.data.Option) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException)

Example 33 with NotFoundException

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

the class SecurityUtil method getUserOfOrganization.

/**
 * Get a user of a certain organization by its ID.
 */
public static Option<User> getUserOfOrganization(SecurityService sec, OrganizationDirectoryService orgDir, String orgId, UserDirectoryService userDir, String userId) {
    final Organization prevOrg = sec.getOrganization();
    try {
        final Organization org = orgDir.getOrganization(orgId);
        sec.setOrganization(org);
        return option(userDir.loadUser(userId));
    } catch (NotFoundException e) {
        return none();
    } finally {
        sec.setOrganization(prevOrg);
    }
}
Also used : JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) Organization(org.opencastproject.security.api.Organization) NotFoundException(org.opencastproject.util.NotFoundException)

Example 34 with NotFoundException

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

the class AbstractJobProducerEndpoint method dispatchJob.

/**
 * @see org.opencastproject.job.api.JobProducer#acceptJob(org.opencastproject.job.api.Job)
 */
@POST
@Path("/dispatch")
public Response dispatchJob(@FormParam("id") long jobId, @FormParam("operation") String jobOperation) throws ServiceRegistryException {
    final JobProducer service = getService();
    if (service == null)
        throw new WebApplicationException(Status.SERVICE_UNAVAILABLE);
    // See if the service is ready to accept anything
    if (!service.isReadyToAcceptJobs(jobOperation)) {
        logger.debug("Service {} is not ready to accept jobs with operation {}", service, jobOperation);
        return Response.status(Status.SERVICE_UNAVAILABLE).build();
    }
    Job job;
    try {
        job = getServiceRegistry().getJob(jobId);
    } catch (NotFoundException e) {
        logger.warn("Unable to find dispatched job {}", jobId);
        return Response.status(Status.NOT_FOUND).build();
    }
    // See if the service has strong feelings about this particular job
    try {
        if (!service.isReadyToAccept(job)) {
            logger.debug("Service {} temporarily refused to accept job {}", service, jobId);
            return Response.status(Status.SERVICE_UNAVAILABLE).build();
        }
    } catch (UndispatchableJobException e) {
        logger.warn("Service {} permanently refused to accept job {}", service, jobId);
        return Response.status(Status.PRECONDITION_FAILED).build();
    }
    service.acceptJob(job);
    return Response.noContent().build();
}
Also used : JobProducer(org.opencastproject.job.api.JobProducer) WebApplicationException(javax.ws.rs.WebApplicationException) UndispatchableJobException(org.opencastproject.serviceregistry.api.UndispatchableJobException) NotFoundException(org.opencastproject.util.NotFoundException) Job(org.opencastproject.job.api.Job) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 35 with NotFoundException

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

the class JobUtilTest method setUp.

@Before
public void setUp() throws Exception {
    serviceRegistry = createNiceMock(ServiceRegistry.class);
    JobImpl job = new JobImpl(20);
    job.setPayload("a payload");
    Job finishedJob1 = new JobImpl(1);
    finishedJob1.setStatus(Status.FINISHED);
    Job finishedJob2 = new JobImpl(2);
    finishedJob2.setStatus(Status.FINISHED);
    Job finishedJob3 = new JobImpl(3);
    finishedJob3.setStatus(Status.FINISHED);
    expect(serviceRegistry.getJob(1)).andReturn(finishedJob1).anyTimes();
    expect(serviceRegistry.getJob(2)).andReturn(finishedJob2).anyTimes();
    expect(serviceRegistry.getJob(3)).andReturn(finishedJob3).anyTimes();
    expect(serviceRegistry.getJob(23)).andThrow(new NotFoundException()).anyTimes();
    expect(serviceRegistry.getJob(20)).andReturn(job).anyTimes();
    replay(serviceRegistry);
}
Also used : NotFoundException(org.opencastproject.util.NotFoundException) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Before(org.junit.Before)

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