Search in sources :

Example 1 with FileProcessorTimeoutException

use of ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException in project irida by phac-nml.

the class DefaultFileProcessingChain method getSettledSequencingObject.

/**
 * Checks the {@link SequenceFile}s for the given {@link SequencingObject}
 * to see if it's files are in the place they should be. Since there's lots
 * of saves going on during the {@link FileProcessingChain} the transaction
 * might not be complete in the time the file is first read.
 *
 * @param sequencingObjectId
 *            the id of the {@link SequencingObject} to check
 * @return the settled {@link SequencingObject}
 * @throws FileProcessorTimeoutException
 *             if the files don't settle in the configured timeout
 */
private SequencingObject getSettledSequencingObject(Long sequencingObjectId) throws FileProcessorTimeoutException {
    boolean filesNotSettled = true;
    Integer waiting = 0;
    SequencingObject sequencingObject;
    do {
        if (waiting > timeout) {
            throw new FileProcessorTimeoutException("Waiting for longer than " + sleepDuration * timeout + "ms, bailing out.  File id " + sequencingObjectId);
        }
        waiting++;
        try {
            Thread.sleep(sleepDuration);
        } catch (InterruptedException e) {
        }
        sequencingObject = sequencingObjectRepository.findOne(sequencingObjectId);
        Set<SequenceFile> files = sequencingObject.getFiles();
        filesNotSettled = files.stream().anyMatch(f -> {
            return !Files.exists(f.getFile());
        });
    } while (filesNotSettled);
    return sequencingObject;
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Files(java.nio.file.Files) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) SequencingObjectRepository(ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) QCEntryRepository(ca.corefacility.bioinformatics.irida.repositories.sample.QCEntryRepository) ArrayList(java.util.ArrayList) FileProcessor(ca.corefacility.bioinformatics.irida.processing.FileProcessor) FileProcessorErrorQCEntry(ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry) List(java.util.List) FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException) FileProcessingChain(ca.corefacility.bioinformatics.irida.processing.FileProcessingChain) FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)

Example 2 with FileProcessorTimeoutException

use of ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException in project irida by phac-nml.

the class DefaultFileProcessingChain method launchChain.

/**
 * {@inheritDoc}
 */
@Override
public List<Exception> launchChain(Long sequencingObjectId) throws FileProcessorTimeoutException {
    List<Exception> ignoredExceptions = new ArrayList<>();
    Integer waiting = 0;
    // file has been persisted in the database.
    while (!sequencingObjectRepository.exists(sequencingObjectId)) {
        if (waiting > timeout) {
            throw new FileProcessorTimeoutException("Waiting for longer than " + sleepDuration * timeout + "ms, bailing out.");
        }
        waiting++;
        try {
            Thread.sleep(sleepDuration);
        } catch (InterruptedException e) {
        }
    }
    for (FileProcessor fileProcessor : fileProcessors) {
        try {
            if (fileProcessor.shouldProcessFile(sequencingObjectId)) {
                SequencingObject settledSequencingObject = getSettledSequencingObject(sequencingObjectId);
                fileProcessor.process(settledSequencingObject);
            }
        } catch (FileProcessorException e) {
            SequencingObject sequencingObject = sequencingObjectRepository.findOne(sequencingObjectId);
            qcRepository.save(new FileProcessorErrorQCEntry(sequencingObject));
            // execution (show the error, but proceed).
            if (fileProcessor.modifiesFile() || fastFail) {
                throw e;
            } else {
                ignoredExceptions.add(e);
                logger.error("File processor [" + fileProcessor.getClass() + "] failed to process [" + sequencingObjectId + "], but proceeding with the remaining processors because the " + "file would not be modified by the processor. Stack trace follows.", e);
            }
        }
    }
    return ignoredExceptions;
}
Also used : FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException) FileProcessor(ca.corefacility.bioinformatics.irida.processing.FileProcessor) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) FileProcessorErrorQCEntry(ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry) ArrayList(java.util.ArrayList) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException)

Example 3 with FileProcessorTimeoutException

use of ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException in project irida by phac-nml.

the class SequenceFileProcessorLauncher method run.

@Override
public void run() {
    // when running in single-threaded mode, the security context should
    // already be populated in the current thread and and we shouldn't
    // have to overwrite and erase the context before execution.
    boolean copiedSecurityContext = true;
    SecurityContext context = SecurityContextHolder.getContext();
    if (context == null || context.getAuthentication() == null) {
        SecurityContextHolder.setContext(securityContext);
    } else {
        copiedSecurityContext = false;
    }
    // proceed with analysis
    try {
        fileProcessingChain.launchChain(sequencingObjectId);
    } catch (FileProcessorTimeoutException e) {
        logger.error("FileProcessingChain did *not* execute -- the transaction opened by SequenceFileService never closed.", e);
    }
    // current thread.
    if (copiedSecurityContext) {
        SecurityContextHolder.clearContext();
    }
}
Also used : FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException) SecurityContext(org.springframework.security.core.context.SecurityContext)

Example 4 with FileProcessorTimeoutException

use of ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException in project irida by phac-nml.

the class DefaultFileProcessingChainTest method testFailWithContinueChain.

@Test
public void testFailWithContinueChain() throws FileProcessorTimeoutException {
    FileProcessingChain fileProcessingChain = new DefaultFileProcessingChain(objectRepository, qcRepository, new FailingFileProcessor());
    when(objectRepository.exists(objectId)).thenReturn(true);
    List<Exception> exceptions = fileProcessingChain.launchChain(1L);
    // exceptions should be ignored in this test
    assertEquals("exactly one exception should have been ignored.", 1, exceptions.size());
    assertTrue("ignored exception should be of type FileProcessorException.", exceptions.iterator().next() instanceof FileProcessorException);
}
Also used : FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) DefaultFileProcessingChain(ca.corefacility.bioinformatics.irida.processing.impl.DefaultFileProcessingChain) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException) FileProcessingChain(ca.corefacility.bioinformatics.irida.processing.FileProcessingChain) DefaultFileProcessingChain(ca.corefacility.bioinformatics.irida.processing.impl.DefaultFileProcessingChain) Test(org.junit.Test)

Aggregations

FileProcessorTimeoutException (ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException)4 FileProcessorException (ca.corefacility.bioinformatics.irida.processing.FileProcessorException)3 FileProcessorErrorQCEntry (ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry)2 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)2 FileProcessingChain (ca.corefacility.bioinformatics.irida.processing.FileProcessingChain)2 FileProcessor (ca.corefacility.bioinformatics.irida.processing.FileProcessor)2 ArrayList (java.util.ArrayList)2 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)1 DefaultFileProcessingChain (ca.corefacility.bioinformatics.irida.processing.impl.DefaultFileProcessingChain)1 QCEntryRepository (ca.corefacility.bioinformatics.irida.repositories.sample.QCEntryRepository)1 SequencingObjectRepository (ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository)1 Files (java.nio.file.Files)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Set (java.util.Set)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1