Search in sources :

Example 6 with FileUploadJob

use of org.opencastproject.fileupload.api.job.FileUploadJob in project opencast by opencast.

the class FileUploadServiceImpl method cleanOutdatedJobs.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.fileupload.api.FileUploadService#cleanOutdatedJobs()
 */
@Override
public void cleanOutdatedJobs() throws IOException {
    File[] workRootFiles = workRoot.listFiles();
    if (workRootFiles == null) {
        logger.trace("No outdated files found in {}", workRoot.getAbsolutePath());
        return;
    }
    for (File dir : workRoot.listFiles()) {
        if (dir.getParentFile().equals(workRoot) && dir.isDirectory()) {
            try {
                // assuming that the dir name is the ID of a job..
                String id = dir.getName();
                if (!isLocked(id)) {
                    // ..true if not in cache or job is in cache and not locked
                    FileUploadJob job = getJob(id);
                    Calendar cal = Calendar.getInstance();
                    cal.add(Calendar.HOUR, -jobMaxTTL);
                    if (job.lastModified() < cal.getTimeInMillis()) {
                        FileUtils.forceDelete(dir);
                        jobCache.remove(id);
                        logger.info("Deleted outdated job {}", id);
                    }
                }
            } catch (Exception e) {
                // something went wrong, so we assume the dir is corrupted
                // ..and delete it right away
                FileUtils.forceDelete(dir);
                logger.info("Deleted corrupted job {}", dir.getName());
            }
        }
    }
}
Also used : FileUploadJob(org.opencastproject.fileupload.api.job.FileUploadJob) Calendar(java.util.Calendar) File(java.io.File) ConfigurationException(org.osgi.service.cm.ConfigurationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileUploadException(org.opencastproject.fileupload.api.exception.FileUploadException)

Example 7 with FileUploadJob

use of org.opencastproject.fileupload.api.job.FileUploadJob in project opencast by opencast.

the class FileUploadServiceImpl method createJob.

// </editor-fold>
/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.fileupload.api.FileUploadService#createJob(String, long, int,
 *      org.opencastproject.mediapackage.MediaPackage, org.opencastproject.mediapackage.MediaPackageElementFlavor)
 */
@Override
public FileUploadJob createJob(String filename, long filesize, int chunksize, MediaPackage mp, MediaPackageElementFlavor flavor) throws FileUploadException {
    FileUploadJob job = new FileUploadJob(filename, filesize, chunksize, mp, flavor);
    logger.info("Creating new upload job: {}", job);
    try {
        // create working dir
        File jobDir = getJobDir(job.getId());
        FileUtils.forceMkdir(jobDir);
        // create empty payload file
        ensureExists(getPayloadFile(job.getId()));
        // create job file
        storeJob(job);
    } catch (FileUploadException e) {
        deleteJob(job.getId());
        throw fileUploadException(Severity.error, "Could not create job file in " + workRoot.getAbsolutePath(), e);
    } catch (IOException e) {
        deleteJob(job.getId());
        throw fileUploadException(Severity.error, "Could not create upload job directory in " + workRoot.getAbsolutePath(), e);
    }
    return job;
}
Also used : FileUploadJob(org.opencastproject.fileupload.api.job.FileUploadJob) IOException(java.io.IOException) File(java.io.File) FileUploadException(org.opencastproject.fileupload.api.exception.FileUploadException)

Aggregations

FileUploadException (org.opencastproject.fileupload.api.exception.FileUploadException)7 FileUploadJob (org.opencastproject.fileupload.api.job.FileUploadJob)7 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 RestQuery (org.opencastproject.util.doc.rest.RestQuery)4 File (java.io.File)3 IOException (java.io.IOException)3 FileNotFoundException (java.io.FileNotFoundException)2 MalformedURLException (java.net.MalformedURLException)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 ConfigurationException (org.osgi.service.cm.ConfigurationException)2 InputStream (java.io.InputStream)1 Calendar (java.util.Calendar)1 FileItemIterator (org.apache.commons.fileupload.FileItemIterator)1 FileItemStream (org.apache.commons.fileupload.FileItemStream)1 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)1