use of ca.corefacility.bioinformatics.irida.exceptions.UploadTimeoutException 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;
}
Aggregations