Search in sources :

Example 16 with GalaxyWorkflowStatus

use of ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus in project irida by phac-nml.

the class AnalysisExecutionScheduledTaskImplTest method testMonitorRunningAnalysesSuccessFinished.

/**
 * Tests successfully switching analysis state to
 * {@link AnalysisState.FINISHED_RUNNING} on success in Galaxy.
 *
 * @throws ExecutionManagerException
 * @throws IridaWorkflowNotFoundException
 */
@Test
public void testMonitorRunningAnalysesSuccessFinished() throws ExecutionManagerException, IridaWorkflowNotFoundException {
    analysisSubmission.setAnalysisState(AnalysisState.RUNNING);
    Map<GalaxyWorkflowState, Set<String>> stateIds = Util.buildStateIdsWithStateFilled(GalaxyWorkflowState.OK, Sets.newHashSet("1"));
    GalaxyWorkflowStatus galaxyWorkflowStatus = new GalaxyWorkflowStatus(GalaxyWorkflowState.OK, stateIds);
    when(analysisSubmissionRepository.findByAnalysisState(AnalysisState.RUNNING)).thenReturn(Arrays.asList(analysisSubmission));
    when(analysisExecutionService.getWorkflowStatus(analysisSubmission)).thenReturn(galaxyWorkflowStatus);
    analysisExecutionScheduledTask.monitorRunningAnalyses();
    assertEquals(AnalysisState.FINISHED_RUNNING, analysisSubmission.getAnalysisState());
    verify(analysisSubmissionRepository).save(analysisSubmission);
}
Also used : Set(java.util.Set) GalaxyWorkflowState(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowState) GalaxyWorkflowStatus(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus) Test(org.junit.Test)

Example 17 with GalaxyWorkflowStatus

use of ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus in project irida by phac-nml.

the class DatabaseSetupGalaxyITService method waitUntilSubmissionComplete.

/**
 * Wait for the given analysis submission to be complete.
 *
 * @param analysisSubmission
 *            The analysis submission to wait for.
 * @throws Exception
 */
public void waitUntilSubmissionComplete(AnalysisSubmission analysisSubmission) throws Exception {
    // 3 minutes
    final int totalSecondsWait = 3 * 60;
    // 2 seconds
    final int pollingTime = 2000;
    Future<Void> waitForHistory = executor.submit(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            GalaxyWorkflowStatus workflowStatus;
            do {
                workflowStatus = analysisExecutionService.getWorkflowStatus(analysisSubmission);
                Thread.sleep(pollingTime);
            } while (!(GalaxyWorkflowState.OK.equals(workflowStatus.getState()) || GalaxyWorkflowState.ERROR.equals(workflowStatus.getState())));
            return null;
        }
    });
    try {
        waitForHistory.get(totalSecondsWait, TimeUnit.SECONDS);
    } catch (TimeoutException e) {
        throw new Exception("Timeout > " + totalSecondsWait + " s when waiting for history for " + analysisSubmission, e);
    }
}
Also used : GalaxyWorkflowStatus(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 18 with GalaxyWorkflowStatus

use of ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus in project irida by phac-nml.

the class AnalysisSubmissionServiceImpl method getPercentCompleteForAnalysisSubmission.

/**
 * {@inheritDoc}
 */
@Override
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#id, 'canReadAnalysisSubmission')")
public float getPercentCompleteForAnalysisSubmission(Long id) throws EntityNotFoundException, ExecutionManagerException, NoPercentageCompleteException {
    AnalysisSubmission analysisSubmission = read(id);
    AnalysisState analysisState = analysisSubmission.getAnalysisState();
    switch(analysisState) {
        case NEW:
        case PREPARING:
        case PREPARED:
        case SUBMITTING:
            return STATE_PERCENTAGE.get(analysisState);
        /**
         * If the analysis is in a state of {@link AnalysisState.RUNNING}
         * then we are able to ask Galaxy for the proportion of jobs that
         * are complete. We can scale this value between RUNNING_PERCENT
         * (10%) and FINISHED_RUNNING_PERCENT (90%) so that after all jobs
         * are complete we are only at 90%. The remaining 10% involves
         * transferring files back to Galaxy.
         *
         * For example, if there are 10 out of 20 jobs finished on Galaxy,
         * then the proportion of jobs complete is 10/20 = 0.5. So, the
         * percent complete for the overall analysis is: percentComplete =
         * 10 + (90 - 10) * 0.5 = 50%.
         *
         * If there are 20 out of 20 jobs finished in Galaxy, then the
         * percent complete is: percentComplete = 10 + (90 - 10) * 1.0 =
         * 90%.
         */
        case RUNNING:
            String workflowHistoryId = analysisSubmission.getRemoteAnalysisId();
            GalaxyWorkflowStatus workflowStatus = galaxyHistoriesService.getStatusForHistory(workflowHistoryId);
            return RUNNING_PERCENT + (FINISHED_RUNNING_PERCENT - RUNNING_PERCENT) * workflowStatus.getProportionComplete();
        case FINISHED_RUNNING:
        case COMPLETING:
        case TRANSFERRED:
        case POST_PROCESSING:
        case COMPLETED:
            return STATE_PERCENTAGE.get(analysisState);
        default:
            throw new NoPercentageCompleteException("No valid percent complete for state " + analysisState);
    }
}
Also used : AnalysisState(ca.corefacility.bioinformatics.irida.model.enums.AnalysisState) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) NoPercentageCompleteException(ca.corefacility.bioinformatics.irida.exceptions.NoPercentageCompleteException) GalaxyWorkflowStatus(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 19 with GalaxyWorkflowStatus

use of ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus in project irida by phac-nml.

the class GalaxyWorkflowsIT method testGetWorkflowStatusComplete.

/**
 * Tests executing a single workflow in Galaxy and getting the status after completion.
 * @throws ExecutionManagerException
 * @throws InterruptedException
 * @throws TimeoutException
 */
@Test
public void testGetWorkflowStatusComplete() throws ExecutionManagerException, TimeoutException, InterruptedException {
    History history = galaxyHistory.newHistoryForWorkflow();
    WorkflowOutputs workflowOutput = runSingleFileTabularWorkflowFilterTool(history, dataFile1, VALID_FILTER_PARAMETER);
    Util.waitUntilHistoryComplete(workflowOutput.getHistoryId(), galaxyHistory, 60);
    // test get workflow status
    GalaxyWorkflowStatus workflowStatus = galaxyHistory.getStatusForHistory(workflowOutput.getHistoryId());
    assertEquals("final workflow state is invalid", GalaxyWorkflowState.OK, workflowStatus.getState());
    assertTrue("final workflow state is invalid", workflowStatus.completedSuccessfully());
}
Also used : WorkflowOutputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowOutputs) History(com.github.jmchilton.blend4j.galaxy.beans.History) GalaxyWorkflowStatus(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus) Test(org.junit.Test)

Example 20 with GalaxyWorkflowStatus

use of ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus in project irida by phac-nml.

the class GalaxyWorkflowsIT method testGetWorkflowStatusError.

/**
 * Tests executing a single workflow in Galaxy and getting an error status after completion.
 * @throws ExecutionManagerException
 * @throws InterruptedException
 * @throws TimeoutException
 */
@Test
public void testGetWorkflowStatusError() throws ExecutionManagerException, TimeoutException, InterruptedException {
    History history = galaxyHistory.newHistoryForWorkflow();
    // no column c2 for this input file, so should give an error
    WorkflowOutputs workflowOutput = runSingleFileTabularWorkflowFilterTool(history, dataFile1, INVALID_FILTER_PARAMETER);
    Util.waitUntilHistoryComplete(workflowOutput.getHistoryId(), galaxyHistory, 60);
    // test get workflow status
    GalaxyWorkflowStatus workflowStatus = galaxyHistory.getStatusForHistory(workflowOutput.getHistoryId());
    assertEquals("final workflow state is invalid", GalaxyWorkflowState.ERROR, workflowStatus.getState());
    assertTrue("final workflow state is invalid", workflowStatus.errorOccurred());
}
Also used : WorkflowOutputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowOutputs) History(com.github.jmchilton.blend4j.galaxy.beans.History) GalaxyWorkflowStatus(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus) Test(org.junit.Test)

Aggregations

GalaxyWorkflowStatus (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus)36 Test (org.junit.Test)32 HistoryDetails (com.github.jmchilton.blend4j.galaxy.beans.HistoryDetails)18 WorkflowOutputs (com.github.jmchilton.blend4j.galaxy.beans.WorkflowOutputs)6 GalaxyWorkflowState (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowState)5 List (java.util.List)5 Set (java.util.Set)5 History (com.github.jmchilton.blend4j.galaxy.beans.History)4 LinkedList (java.util.LinkedList)4 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)3 Dataset (com.github.jmchilton.blend4j.galaxy.beans.Dataset)3 ArrayList (java.util.ArrayList)3 TimeoutException (java.util.concurrent.TimeoutException)2 ExecutionManagerException (ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)1 NoPercentageCompleteException (ca.corefacility.bioinformatics.irida.exceptions.NoPercentageCompleteException)1 AnalysisState (ca.corefacility.bioinformatics.irida.model.enums.AnalysisState)1 HistoryContentsProvenance (com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance)1 ToolParameter (com.github.jmchilton.blend4j.galaxy.beans.ToolParameter)1 Path (java.nio.file.Path)1 Future (java.util.concurrent.Future)1