use of ca.corefacility.bioinformatics.irida.exceptions.UploadException in project irida by phac-nml.
the class AnalysisCollectionServiceGalaxy method uploadSequenceFilesPaired.
/**
* Uploads a list of paired sequence files belonging to the given samples to
* Galaxy.
*
* @param sampleSequenceFilesPaired
* A map between {@link Sample} and {@link SequenceFilePair}.
* @param workflowHistory
* The history to upload the sequence files into.
* @param workflowLibrary
* A temporary library to upload files into.
* @return A CollectionResponse for the dataset collection constructed from
* the given files.
* @throws ExecutionManagerException
* If there was an error uploading the files.
*/
public CollectionResponse uploadSequenceFilesPaired(Map<Sample, ? extends IridaSequenceFilePair> sampleSequenceFilesPaired, History workflowHistory, Library workflowLibrary) throws ExecutionManagerException {
CollectionDescription description = new CollectionDescription();
description.setCollectionType(DatasetCollectionType.LIST_PAIRED.toString());
description.setName(COLLECTION_NAME_PAIRED);
Map<Sample, Path> samplesMapPairForward = new HashMap<>();
Map<Sample, Path> samplesMapPairReverse = new HashMap<>();
Set<Path> pathsToUpload = new HashSet<>();
for (Sample sample : sampleSequenceFilesPaired.keySet()) {
IridaSequenceFilePair sequenceFilePair = sampleSequenceFilesPaired.get(sample);
IridaSequenceFile fileForward = sequenceFilePair.getForwardSequenceFile();
IridaSequenceFile fileReverse = sequenceFilePair.getReverseSequenceFile();
samplesMapPairForward.put(sample, fileForward.getFile());
samplesMapPairReverse.put(sample, fileReverse.getFile());
pathsToUpload.add(fileForward.getFile());
pathsToUpload.add(fileReverse.getFile());
}
// upload files to library and then to a history
Map<Path, String> pathHistoryDatasetId = galaxyHistoriesService.filesToLibraryToHistory(pathsToUpload, InputFileType.FASTQ_SANGER, workflowHistory, workflowLibrary, DataStorage.LOCAL);
for (Sample sample : sampleSequenceFilesPaired.keySet()) {
Path fileForward = samplesMapPairForward.get(sample);
Path fileReverse = samplesMapPairReverse.get(sample);
if (!pathHistoryDatasetId.containsKey(fileForward)) {
throw new UploadException("Error, no corresponding history item found for " + fileForward);
} else if (!pathHistoryDatasetId.containsKey(fileReverse)) {
throw new UploadException("Error, no corresponding history item found for " + fileReverse);
} else {
String datasetHistoryIdForward = pathHistoryDatasetId.get(fileForward);
String datasetHistoryIdReverse = pathHistoryDatasetId.get(fileReverse);
CollectionElement pairedElement = new CollectionElement();
pairedElement.setName(sample.getSampleName());
pairedElement.setCollectionType(DatasetCollectionType.PAIRED.toString());
HistoryDatasetElement datasetElementForward = new HistoryDatasetElement();
datasetElementForward.setId(datasetHistoryIdForward);
datasetElementForward.setName(FORWARD_NAME);
pairedElement.addCollectionElement(datasetElementForward);
HistoryDatasetElement datasetElementReverse = new HistoryDatasetElement();
datasetElementReverse.setId(datasetHistoryIdReverse);
datasetElementReverse.setName(REVERSE_NAME);
pairedElement.addCollectionElement(datasetElementReverse);
description.addDatasetElement(pairedElement);
}
}
return galaxyHistoriesService.constructCollection(description, workflowHistory);
}
use of ca.corefacility.bioinformatics.irida.exceptions.UploadException in project irida by phac-nml.
the class ExportUploadService method uploadString.
/**
* Upload a string to remote ftp client
*
* @param client
* {@link FTPClient} to use for upload
* @param filename
* name of file to create
* @param content
* content of file to create
* @throws UploadException
* if file could not be uploaded
*/
private void uploadString(FTPClient client, String filename, String content) throws UploadException {
int tries = 0;
boolean done = false;
do {
tries++;
try (ByteArrayInputStream stringStream = new ByteArrayInputStream(content.getBytes())) {
client.storeFile(filename, stringStream);
done = true;
} catch (Exception e) {
String reply = client.getReplyString();
logger.error("Error uploading file: " + reply, e);
if (tries >= MAX_RETRIES) {
throw new UploadException("Could not upload file " + filename + " : " + reply, e);
}
}
} while (!done);
}
use of ca.corefacility.bioinformatics.irida.exceptions.UploadException in project irida by phac-nml.
the class ExportUploadService method uploadPath.
/**
* Upload a file {@link Path} to a remote ftp client
*
* @param client {@link FTPClient} to upload with
* @param filename name of file to create
* @param path {@link Path} to upload
* @throws UploadException if file could not be uploaded
*/
private void uploadPath(FTPClient client, String filename, Path path) throws UploadException {
int tries = 0;
boolean done = false;
do {
tries++;
try (InputStream stream = Files.newInputStream(path)) {
client.storeFile(filename, stream);
done = true;
} catch (Exception e) {
String reply = client.getReplyString();
logger.error("Error uploading file: " + reply, e);
if (tries >= MAX_RETRIES) {
throw new UploadException("Could not upload file " + filename + " : " + reply, e);
}
}
} while (!done);
}
use of ca.corefacility.bioinformatics.irida.exceptions.UploadException 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;
}
use of ca.corefacility.bioinformatics.irida.exceptions.UploadException in project irida by phac-nml.
the class GalaxyLibrariesService method fileToLibrary.
/**
* Uploads the given file to a library with the given information.
*
* @param path
* The path of the file to upload.
* @param fileType
* The type of the file to upload.
* @param library
* The library to upload the file into.
* @param dataStorage
* The {@link DataStorage} method to apply to this dataset.
* @return A dataset id for the dataset in this library.
* @throws UploadException
* If there was an issue uploading the file to the library.
*/
public String fileToLibrary(Path path, InputFileType fileType, Library library, DataStorage dataStorage) throws UploadException {
checkNotNull(path, "path is null");
checkNotNull(fileType, "fileType is null");
checkNotNull(library, "library is null");
checkNotNull(library.getId(), "library id is null");
checkState(path.toFile().exists(), "path " + path + " does not exist");
File file = path.toFile();
try {
LibraryContent rootContent = librariesClient.getRootFolder(library.getId());
FilesystemPathsLibraryUpload upload = new FilesystemPathsLibraryUpload();
upload.setFolderId(rootContent.getId());
upload.setContent(file.getAbsolutePath());
upload.setName(file.getName());
upload.setLinkData(DataStorage.LOCAL.equals(dataStorage));
upload.setFileType(fileType.toString());
GalaxyObject uploadObject = librariesClient.uploadFilesystemPaths(library.getId(), upload);
return uploadObject.getId();
} catch (RuntimeException e) {
throw new UploadException(e);
}
}
Aggregations