use of com.github.jmchilton.blend4j.galaxy.beans.LibraryDataset in project irida by phac-nml.
the class GalaxyLibrariesServiceIT method testFileToLibrarySuccess.
/**
* Tests successful upload of a file to a Galaxy Library.
*
* @throws UploadException
* @throws GalaxyDatasetException
*/
@Test
public void testFileToLibrarySuccess() throws UploadException, GalaxyDatasetException {
String filename = dataFile.toFile().getName();
Library library = buildEmptyLibrary("testFileToLibrarySuccess");
String datasetId = galaxyLibrariesService.fileToLibrary(dataFile, FILE_TYPE, library, DataStorage.LOCAL);
assertNotNull(datasetId);
LibraryDataset actualDataset = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient().showDataset(library.getId(), datasetId);
assertNotNull(actualDataset);
assertEquals(filename, actualDataset.getName());
assertEquals(Long.toString(dataFile.toFile().length()), actualDataset.getFileSize());
}
use of com.github.jmchilton.blend4j.galaxy.beans.LibraryDataset 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 com.github.jmchilton.blend4j.galaxy.beans.LibraryDataset in project irida by phac-nml.
the class GalaxyLibrariesServiceIT method testFilesToLibraryWaitSuccess.
/**
* Tests successful upload of a list of files to a Galaxy Library.
*
* @throws UploadException
* @throws GalaxyDatasetException
*/
@Test
public void testFilesToLibraryWaitSuccess() throws UploadException, GalaxyDatasetException {
Library library = buildEmptyLibrary("testFilesToLibraryWaitSuccess");
Map<Path, String> datasetsMap = galaxyLibrariesService.filesToLibraryWait(Sets.newHashSet(dataFile, dataFile2), FILE_TYPE, library, DataStorage.LOCAL);
assertNotNull(datasetsMap);
assertEquals(2, datasetsMap.size());
String datasetId1 = datasetsMap.get(dataFile);
String datasetId2 = datasetsMap.get(dataFile2);
LibraryDataset actualDataset1 = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient().showDataset(library.getId(), datasetId1);
assertNotNull(actualDataset1);
LibraryDataset actualDataset2 = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient().showDataset(library.getId(), datasetId2);
assertNotNull(actualDataset2);
}
Aggregations