Search in sources :

Example 1 with UploadErrorException

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

the class GalaxyLibrariesService method filesToLibraryWait.

/**
 * Uploads a set of files to a given library, waiting until all uploads are
 * complete.
 *
 * @param paths
 *            The set of paths to upload.
 * @param fileType
 *            The file type of the file to upload.
 * @param library
 *            The library to initially upload the file into.
 * @param dataStorage
 *            The type of DataStorage strategy to use.
 * @return An @{link Map} of paths and ids for each dataset object in this
 *         library.
 * @throws UploadException
 *             If there was an issue uploading the file to Galaxy.
 */
public Map<Path, String> filesToLibraryWait(Set<Path> paths, InputFileType fileType, Library library, DataStorage dataStorage) throws UploadException {
    checkNotNull(paths, "paths is null");
    final int pollingTimeMillis = libraryPollingTime * 1000;
    Map<Path, String> datasetLibraryIdsMap = new HashMap<>();
    try {
        // upload all files to library first
        for (Path path : paths) {
            String datasetLibraryId = fileToLibrary(path, fileType, library, dataStorage);
            datasetLibraryIdsMap.put(path, datasetLibraryId);
        }
        Future<Void> waitForLibraries = executor.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                // wait for uploads to finish
                for (Path path : paths) {
                    String datasetLibraryId = datasetLibraryIdsMap.get(path);
                    LibraryDataset libraryDataset = librariesClient.showDataset(library.getId(), datasetLibraryId);
                    while (!LIBRARY_OK_STATE.equals(libraryDataset.getState())) {
                        logger.trace("Waiting for library dataset " + libraryDataset.getId() + " to be finished processing, in state " + libraryDataset.getState());
                        Thread.sleep(pollingTimeMillis);
                        libraryDataset = librariesClient.showDataset(library.getId(), datasetLibraryId);
                        if (LIBRARY_FAIL_STATES.contains(libraryDataset.getState())) {
                            throw new UploadErrorException("Error: upload to Galaxy library id=" + library.getId() + " name=" + library.getName() + " for dataset id=" + datasetLibraryId + " name=" + libraryDataset.getName() + " failed with state=" + libraryDataset.getState());
                        }
                    }
                }
                return null;
            }
        });
        waitForLibraries.get(libraryUploadTimeout, TimeUnit.SECONDS);
    } catch (RuntimeException e) {
        throw new UploadException(e);
    } catch (TimeoutException e) {
        throw new UploadTimeoutException("Timeout while uploading, time limit = " + libraryUploadTimeout + " seconds", e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof UploadErrorException) {
            throw (UploadErrorException) e.getCause();
        } else {
            throw new UploadException(e);
        }
    } catch (InterruptedException e) {
        throw new UploadException(e);
    }
    return datasetLibraryIdsMap;
}
Also used : Path(java.nio.file.Path) UploadTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.UploadTimeoutException) HashMap(java.util.HashMap) UploadErrorException(ca.corefacility.bioinformatics.irida.exceptions.UploadErrorException) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException) DeleteGalaxyObjectFailedException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.DeleteGalaxyObjectFailedException) TimeoutException(java.util.concurrent.TimeoutException) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException) CreateLibraryException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.CreateLibraryException) UploadTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.UploadTimeoutException) ExecutionException(java.util.concurrent.ExecutionException) UploadErrorException(ca.corefacility.bioinformatics.irida.exceptions.UploadErrorException) LibraryDataset(com.github.jmchilton.blend4j.galaxy.beans.LibraryDataset) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) UploadTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.UploadTimeoutException)

Aggregations

UploadErrorException (ca.corefacility.bioinformatics.irida.exceptions.UploadErrorException)1 UploadException (ca.corefacility.bioinformatics.irida.exceptions.UploadException)1 UploadTimeoutException (ca.corefacility.bioinformatics.irida.exceptions.UploadTimeoutException)1 CreateLibraryException (ca.corefacility.bioinformatics.irida.exceptions.galaxy.CreateLibraryException)1 DeleteGalaxyObjectFailedException (ca.corefacility.bioinformatics.irida.exceptions.galaxy.DeleteGalaxyObjectFailedException)1 LibraryDataset (com.github.jmchilton.blend4j.galaxy.beans.LibraryDataset)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1