Search in sources :

Example 1 with HistoryContentsProvenance

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance in project irida by phac-nml.

the class GalaxyWorkflowsIT method testExecuteWorkflowChangeToolParameter.

/**
 * Tests executing a single workflow in Galaxy and changing a single tool
 * parameter.
 *
 * @throws ExecutionManagerException
 */
@Test
public void testExecuteWorkflowChangeToolParameter() throws ExecutionManagerException {
    String toolId = "Grep1";
    String workflowId = localGalaxy.getSingleInputWorkflowId();
    String workflowInputLabel = localGalaxy.getSingleInputWorkflowLabel();
    Map<String, ToolParameter> toolParameters = ImmutableMap.of(toolId, new ToolParameter("pattern", "^#"));
    WorkflowOutputs workflowOutput = runSingleFileWorkflow(dataFile1, FILE_TYPE, workflowId, workflowInputLabel, toolParameters);
    assertNotNull("workflowOutput should not be null", workflowOutput);
    assertNotNull("workflowOutput history id should not be null", workflowOutput.getHistoryId());
    // history should exist
    HistoryDetails historyDetails = historiesClient.showHistory(workflowOutput.getHistoryId());
    assertNotNull("historyDetails for the history for the workflow should not be null", historyDetails);
    // outputs should exist
    assertNotNull("outputIds for the workflow should not be null", workflowOutput.getOutputIds());
    assertTrue("there should exist output dataset ids for the workflow", workflowOutput.getOutputIds().size() > 0);
    // each output dataset should exist
    for (String outputId : workflowOutput.getOutputIds()) {
        Dataset dataset = historiesClient.showDataset(workflowOutput.getHistoryId(), outputId);
        assertNotNull("the output dataset should exist", dataset);
        HistoryContentsProvenance provenance = historiesClient.showProvenance(workflowOutput.getHistoryId(), dataset.getId());
        if (toolId.equals(provenance.getToolId())) {
            Map<String, Object> parametersMap = provenance.getParameters();
            assertEquals("pattern parameter is correct", "\"^#\"", parametersMap.get("pattern"));
        }
    }
    // test get workflow status
    GalaxyWorkflowStatus workflowStatus = galaxyHistory.getStatusForHistory(workflowOutput.getHistoryId());
    float proportionComplete = workflowStatus.getProportionComplete();
    assertTrue("the workflow proportion complete should be between 0 and 1", 0.0f <= proportionComplete && proportionComplete <= 1.0f);
}
Also used : WorkflowOutputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowOutputs) HistoryDetails(com.github.jmchilton.blend4j.galaxy.beans.HistoryDetails) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) ToolParameter(com.github.jmchilton.blend4j.galaxy.beans.ToolParameter) GalaxyWorkflowStatus(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus) HistoryContentsProvenance(com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance) Test(org.junit.Test)

Example 2 with HistoryContentsProvenance

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance in project irida by phac-nml.

the class AnalysisProvenanceServiceGalaxyTest method testBuildSingleStepToolExecutionStrangeDataStructureDoToString.

@Test
public void testBuildSingleStepToolExecutionStrangeDataStructureDoToString() throws ExecutionManagerException {
    final HistoryContents hc = new HistoryContents();
    hc.setName(FILENAME);
    final HistoryContentsProvenance hcp = new HistoryContentsProvenance();
    hcp.setParameters(ImmutableMap.of("akey", "[[\"avalue\"]]"));
    final JobDetails jd = new JobDetails();
    jd.setCommandLine("");
    when(galaxyHistoriesService.showHistoryContents(any(String.class))).thenReturn(Lists.newArrayList(hc));
    when(galaxyHistoriesService.showProvenance(any(String.class), any(String.class))).thenReturn(hcp);
    when(toolsClient.showTool(any(String.class))).thenReturn(new Tool());
    when(jobsClient.showJob(any(String.class))).thenReturn(jd);
    final ToolExecution toolExecution = provenanceService.buildToolExecutionForOutputFile(analysisSubmission(), analysisOutputFile());
    assertTrue("tool execution should have the specified parameter.", toolExecution.getExecutionTimeParameters().containsKey("akey"));
    assertEquals("tool execution parameter should be specified value.", "[[\"avalue\"]]", toolExecution.getExecutionTimeParameters().get("akey"));
}
Also used : ToolExecution(ca.corefacility.bioinformatics.irida.model.workflow.analysis.ToolExecution) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) HistoryContentsProvenance(com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance) JobDetails(com.github.jmchilton.blend4j.galaxy.beans.JobDetails) Tool(com.github.jmchilton.blend4j.galaxy.beans.Tool) Test(org.junit.Test)

Example 3 with HistoryContentsProvenance

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance in project irida by phac-nml.

the class AnalysisProvenanceServiceGalaxyTest method testCantFindTools.

@Test(expected = ExecutionManagerException.class)
public void testCantFindTools() throws ExecutionManagerException {
    final HistoryContents hc = new HistoryContents();
    hc.setName(FILENAME);
    when(galaxyHistoriesService.showHistoryContents(any(String.class))).thenReturn(Lists.newArrayList(hc));
    when(galaxyHistoriesService.showProvenance(any(String.class), any(String.class))).thenReturn(new HistoryContentsProvenance());
    when(toolsClient.showTool(any(String.class))).thenThrow(new RuntimeException());
    provenanceService.buildToolExecutionForOutputFile(analysisSubmission(), analysisOutputFile());
}
Also used : HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) HistoryContentsProvenance(com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance) Test(org.junit.Test)

Example 4 with HistoryContentsProvenance

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance in project irida by phac-nml.

the class AnalysisProvenanceServiceGalaxy method buildToolExecutionForHistoryStep.

/**
 * Build up a complete *tree* of ToolExecution from Galaxy's history
 * contents provenance objects. Recursively follows predecessors from the
 * current history.
 *
 * @param toolDetails
 *            the details of the current tool to build up tool execution
 *            details for.
 * @param currentProvenance
 *            the provenance that corresponds to the tool details.
 * @param historyId
 *            the Galaxy ID we should use to extract tool execution
 *            information.
 * @return the entire tree of ToolExecutions for the tool and its
 *         provenance.
 * @throws ExecutionManagerException
 *             if we could not get the history contents provenance or the
 *             tool details for a predecessor of the current tool details or
 *             provenance.
 */
private ToolExecution buildToolExecutionForHistoryStep(final Tool toolDetails, final HistoryContentsProvenance currentProvenance, final String historyId) throws ExecutionManagerException {
    final Map<String, Set<String>> predecessors = getPredecessors(currentProvenance);
    final Map<String, Object> parameters = currentProvenance.getParameters();
    // remove keys from parameters that are Galaxy-related (and thus
    // ignorable), or keys that *match* input keys (as mentioned in
    // getPredecessors, the input keys are going to have a numeric
    // suffix and so don't equal the key that we want to remove from the
    // key set):
    /* @formatter:off */
    final Set<String> parameterKeys = parameters.keySet().stream().filter(k -> !PARAMETERS_TO_IGNORE.contains(k)).filter(k -> !predecessors.keySet().stream().anyMatch(p -> k.contains(p))).collect(Collectors.toSet());
    /* @formatter:on */
    final Map<String, Object> paramValues = new HashMap<>();
    for (final String parameterKey : parameterKeys) {
        paramValues.put(parameterKey, parameters.get(parameterKey));
    }
    final Set<ToolExecution> prevSteps = new HashSet<>();
    final String toolName = toolDetails.getName();
    final String toolVersion = toolDetails.getVersion();
    final String jobId = currentProvenance.getJobId();
    final JobDetails jobDetails = jobsClient.showJob(jobId);
    final String commandLine = jobDetails.getCommandLine();
    final Map<String, String> paramStrings = buildParamMap(paramValues);
    for (final String predecessorKey : predecessors.keySet()) {
        // arbitrarily select one of the predecessors from the set, then
        // recurse on that predecessor:
        final String predecessor = predecessors.get(predecessorKey).iterator().next();
        final HistoryContentsProvenance previousProvenance = galaxyHistoriesService.showProvenance(historyId, predecessor);
        final Tool previousToolDetails = toolsClient.showTool(previousProvenance.getToolId());
        final ToolExecution toolExecution = buildToolExecutionForHistoryStep(previousToolDetails, previousProvenance, historyId);
        prevSteps.add(toolExecution);
    }
    return new ToolExecution(prevSteps, toolName, toolVersion, jobId, paramStrings, commandLine);
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) ExecutionManagerException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) LoggerFactory(org.slf4j.LoggerFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) GalaxyHistoriesService(ca.corefacility.bioinformatics.irida.pipeline.upload.galaxy.GalaxyHistoriesService) JobDetails(com.github.jmchilton.blend4j.galaxy.beans.JobDetails) Tool(com.github.jmchilton.blend4j.galaxy.beans.Tool) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) HashSet(java.util.HashSet) List(java.util.List) ToolsClient(com.github.jmchilton.blend4j.galaxy.ToolsClient) Map(java.util.Map) ToolExecution(ca.corefacility.bioinformatics.irida.model.workflow.analysis.ToolExecution) IridaToolParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter) JsonToken(com.fasterxml.jackson.core.JsonToken) JobsClient(com.github.jmchilton.blend4j.galaxy.JobsClient) HistoryContentsProvenance(com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance) Joiner(com.google.common.base.Joiner) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) JobDetails(com.github.jmchilton.blend4j.galaxy.beans.JobDetails) HistoryContentsProvenance(com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance) ToolExecution(ca.corefacility.bioinformatics.irida.model.workflow.analysis.ToolExecution) HashSet(java.util.HashSet) Tool(com.github.jmchilton.blend4j.galaxy.beans.Tool)

Example 5 with HistoryContentsProvenance

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance in project irida by phac-nml.

the class GalaxyJobErrorsService method createNewJobErrors.

/**
 * Get any {@link JobError} associated with an {@link AnalysisSubmission}
 *
 * @param analysisSubmission {@link AnalysisSubmission} to search for job failures
 * @return List of {@link JobError} objects associated with {@link AnalysisSubmission}
 */
public List<JobError> createNewJobErrors(AnalysisSubmission analysisSubmission) {
    String historyId = analysisSubmission.getRemoteAnalysisId();
    HistoryDetails historyDetails = historiesClient.showHistory(historyId);
    List<String> erroredDatasetIds = historyDetails.getStateIds().get(GalaxyWorkflowState.ERROR.toString());
    List<HistoryContentsProvenance> provenances = erroredDatasetIds.stream().map((x) -> historiesClient.showProvenance(historyId, x)).collect(Collectors.toList());
    Map<String, List<HistoryContentsProvenance>> jobIdProvenancesMap = provenances.stream().collect(Collectors.groupingBy(HistoryContentsProvenance::getJobId));
    List<JobError> jobErrors = new ArrayList<>();
    for (Map.Entry<String, List<HistoryContentsProvenance>> entry : jobIdProvenancesMap.entrySet()) {
        String jobId = entry.getKey();
        JobDetails jobDetails = jobsClient.showJob(jobId);
        HistoryContentsProvenance p = entry.getValue().iterator().next();
        Tool tool = toolsClient.showTool(p.getToolId());
        jobErrors.add(new JobError(analysisSubmission, jobDetails, p, tool));
    }
    return jobErrors;
}
Also used : AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) JobDetails(com.github.jmchilton.blend4j.galaxy.beans.JobDetails) Tool(com.github.jmchilton.blend4j.galaxy.beans.Tool) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) ToolsClient(com.github.jmchilton.blend4j.galaxy.ToolsClient) JobError(ca.corefacility.bioinformatics.irida.model.workflow.analysis.JobError) Map(java.util.Map) HistoryDetails(com.github.jmchilton.blend4j.galaxy.beans.HistoryDetails) GalaxyWorkflowState(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowState) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) JobsClient(com.github.jmchilton.blend4j.galaxy.JobsClient) HistoryContentsProvenance(com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance) ArrayList(java.util.ArrayList) JobError(ca.corefacility.bioinformatics.irida.model.workflow.analysis.JobError) HistoryContentsProvenance(com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance) JobDetails(com.github.jmchilton.blend4j.galaxy.beans.JobDetails) HistoryDetails(com.github.jmchilton.blend4j.galaxy.beans.HistoryDetails) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Tool(com.github.jmchilton.blend4j.galaxy.beans.Tool)

Aggregations

HistoryContentsProvenance (com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance)10 HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)8 Tool (com.github.jmchilton.blend4j.galaxy.beans.Tool)8 JobDetails (com.github.jmchilton.blend4j.galaxy.beans.JobDetails)7 Test (org.junit.Test)7 ToolExecution (ca.corefacility.bioinformatics.irida.model.workflow.analysis.ToolExecution)6 List (java.util.List)3 ExecutionManagerException (ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)2 JobsClient (com.github.jmchilton.blend4j.galaxy.JobsClient)2 ToolsClient (com.github.jmchilton.blend4j.galaxy.ToolsClient)2 HistoryDetails (com.github.jmchilton.blend4j.galaxy.beans.HistoryDetails)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 JobError (ca.corefacility.bioinformatics.irida.model.workflow.analysis.JobError)1 IridaToolParameter (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter)1 GalaxyWorkflowState (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowState)1 GalaxyWorkflowStatus (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus)1 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)1 GalaxyHistoriesService (ca.corefacility.bioinformatics.irida.pipeline.upload.galaxy.GalaxyHistoriesService)1