Search in sources :

Example 1 with LibraryDataset

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());
}
Also used : LibraryDataset(com.github.jmchilton.blend4j.galaxy.beans.LibraryDataset) Library(com.github.jmchilton.blend4j.galaxy.beans.Library) Test(org.junit.Test)

Example 2 with LibraryDataset

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;
}
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)

Example 3 with LibraryDataset

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);
}
Also used : Path(java.nio.file.Path) LibraryDataset(com.github.jmchilton.blend4j.galaxy.beans.LibraryDataset) Library(com.github.jmchilton.blend4j.galaxy.beans.Library) Test(org.junit.Test)

Aggregations

LibraryDataset (com.github.jmchilton.blend4j.galaxy.beans.LibraryDataset)3 Library (com.github.jmchilton.blend4j.galaxy.beans.Library)2 Path (java.nio.file.Path)2 Test (org.junit.Test)2 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 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1