Search in sources :

Example 6 with HistoryContentsProvenance

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

the class AnalysisProvenanceServiceGalaxyTest method testBuildSingleStepToolExecutionListParameters.

@Test
public void testBuildSingleStepToolExecutionListParameters() throws ExecutionManagerException {
    final HistoryContents hc = new HistoryContents();
    hc.setName(FILENAME);
    final HistoryContentsProvenance hcp = new HistoryContentsProvenance();
    hcp.setParameters(ImmutableMap.<String, Object>builder().put("akey", "[\"avalue\"]").put("akey2", Lists.newArrayList("avalue2")).put("akey3", "[]").put("akey4", Lists.newArrayList()).put("akey5", "[\"avalue5.1\", \"avalue5.2\"]").put("akey6", Lists.newArrayList("avalue6.1", "avalue6.2")).build());
    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"));
    assertTrue("tool execution should have the specified parameter.", toolExecution.getExecutionTimeParameters().containsKey("akey2"));
    assertEquals("tool execution parameter should be specified value.", "[avalue2]", toolExecution.getExecutionTimeParameters().get("akey2"));
    assertEquals("tool execution parameter should be specified value.", "[]", toolExecution.getExecutionTimeParameters().get("akey3"));
    assertEquals("tool execution parameter should be specified value.", "[]", toolExecution.getExecutionTimeParameters().get("akey4"));
    assertEquals("tool execution parameter should be specified value.", "[avalue5.1, avalue5.2]", toolExecution.getExecutionTimeParameters().get("akey5"));
    assertEquals("tool execution parameter should be specified value.", "[avalue6.1, avalue6.2]", toolExecution.getExecutionTimeParameters().get("akey6"));
    assertTrue("Tool execution should be considered input step, no predecessors.", toolExecution.isInputTool());
}
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 7 with HistoryContentsProvenance

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

the class AnalysisProvenanceServiceGalaxyTest method testBuildSingleStepToolExecutionOneParameterOnePredecessor.

@Test
public void testBuildSingleStepToolExecutionOneParameterOnePredecessor() throws ExecutionManagerException {
    final HistoryContents hc = new HistoryContents();
    hc.setName(FILENAME);
    hc.setId("historyContentsId");
    final HistoryContentsProvenance hcpWithPredecessor = new HistoryContentsProvenance();
    hcpWithPredecessor.setParameters(ImmutableMap.of("akey", (Object) ImmutableMap.of("id", "previousKey")));
    final HistoryContentsProvenance hcpWithoutPredecessor = new HistoryContentsProvenance();
    hcpWithoutPredecessor.setParameters(ImmutableMap.of("akey", (Object) "value"));
    when(galaxyHistoriesService.showHistoryContents(any(String.class))).thenReturn(Lists.newArrayList(hc));
    when(galaxyHistoriesService.showProvenance(any(String.class), eq("historyContentsId"))).thenReturn(hcpWithPredecessor);
    when(galaxyHistoriesService.showProvenance(any(String.class), eq("previousKey"))).thenReturn(hcpWithoutPredecessor);
    when(jobsClient.showJob(any(String.class))).thenReturn(new JobDetails());
    when(toolsClient.showTool(any(String.class))).thenReturn(new Tool());
    final ToolExecution toolExecution = provenanceService.buildToolExecutionForOutputFile(analysisSubmission(), analysisOutputFile());
    assertFalse("tool execution should not have an ID parameter.", toolExecution.getExecutionTimeParameters().containsKey("akey"));
    assertFalse("tool execution should not have an ID parameter.", toolExecution.getExecutionTimeParameters().containsKey("akey.id"));
    assertFalse("Tool execution has one predecessor, not input step.", toolExecution.isInputTool());
    final ToolExecution predecessor = toolExecution.getPreviousSteps().iterator().next();
    assertTrue("predecessor step is input step.", predecessor.isInputTool());
}
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 8 with HistoryContentsProvenance

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

the class AnalysisProvenanceServiceGalaxyTest method testBuildSingleStepToolExecutionComplexParameters.

@Test
public void testBuildSingleStepToolExecutionComplexParameters() throws ExecutionManagerException {
    final HistoryContents hc = new HistoryContents();
    hc.setName(FILENAME);
    final HistoryContentsProvenance hcp = new HistoryContentsProvenance();
    final Map<String, Object> mapWithNullValue = new HashMap<>();
    mapWithNullValue.put("key", null);
    final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    builder.put("akey", (Object) "avalue").put("anotherKey", (Object) "{\"key\": \"value\"}").put("thirdKey", (Object) ImmutableMap.of("key", "{\"key\":\"value\"}")).put("fourthKey", (Object) "[{\"key\":\"value\"}]").put("fifthKey", (Object) mapWithNullValue).put("abadkey", (Object) "[{\"key\":\"value\"]").put("listKey", (Object) ImmutableList.of(ImmutableMap.of("key", "value"))).put("k", (Object) "value-lower").put("K", (Object) "value-upper").put("\\\\keyWithBackslash", (Object) "value-backslash-lower").put("\\\\KeyWithBackslash", (Object) "value-backslash-upper").put("MULTIPLE_UPPER_case", (Object) "upper-case-values!");
    hcp.setParameters(builder.build());
    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(new JobDetails());
    final ToolExecution toolExecution = provenanceService.buildToolExecutionForOutputFile(analysisSubmission(), analysisOutputFile());
    final Map<String, String> params = toolExecution.getExecutionTimeParameters();
    assertTrue("tool execution should have the specified parameter.", params.containsKey("akey"));
    assertEquals("tool execution parameter should be specified value.", "avalue", params.get("akey"));
    assertTrue("tool execution should have the specified parameter.", params.containsKey("anotherKey.key"));
    assertEquals("tool execution parameter should be specified value.", "value", params.get("anotherKey.key"));
    assertTrue("tool execution should have the specified parameter.", params.containsKey("thirdKey.key.key"));
    assertEquals("tool execution parameter should be specified value.", "value", params.get("thirdKey.key.key"));
    assertTrue("tool execution should have the specified parameter.", params.containsKey("fourthKey.key"));
    assertEquals("tool execution parameter should be specified value.", "value", params.get("fourthKey.key"));
    assertTrue("tool execution should have the specified parameter.", params.containsKey("fifthKey.key"));
    assertEquals("tool execution parameter should be specified value.", AnalysisProvenanceServiceGalaxy.emptyValuePlaceholder(), params.get("fifthKey.key"));
    assertTrue("tool execution should have the specified parameter.", params.containsKey("abadkey"));
    assertEquals("tool execution parameter should be specified value.", "[{\"key\":\"value\"]", params.get("abadkey"));
    assertTrue("tool execution should have the specified parameter.", params.containsKey("listKey.key"));
    assertEquals("tool execution parameter should be specified value.", "value", params.get("listKey.key"));
    assertTrue("tool execution should have the specified parameter.", params.containsKey("k"));
    assertEquals("tool execution parameter should be specified value.", "value-lower", params.get("k"));
    assertTrue("tool execution should have the specified parameter.", params.containsKey("K"));
    assertEquals("tool execution parameter should be specified value.", "value-upper", params.get("K"));
    assertTrue("tool execution should have the specified parameter.", params.containsKey("\\\\keyWithBackslash"));
    assertEquals("tool execution parameter should be specified value.", "value-backslash-lower", params.get("\\\\keyWithBackslash"));
    assertTrue("tool execution should have the specified parameter.", params.containsKey("\\\\KeyWithBackslash"));
    assertEquals("tool execution parameter should be specified value.", "value-backslash-upper", params.get("\\\\KeyWithBackslash"));
    assertTrue("tool execution should have the specified parameter.", params.containsKey("MULTIPLE_UPPER_case"));
    assertEquals("tool execution parameter should be specified value.", "upper-case-values!", params.get("MULTIPLE_UPPER_case"));
    assertTrue("Tool execution should be considered input step, no predecessors.", toolExecution.isInputTool());
}
Also used : HashMap(java.util.HashMap) 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) ImmutableMap(com.google.common.collect.ImmutableMap) JobDetails(com.github.jmchilton.blend4j.galaxy.beans.JobDetails) Tool(com.github.jmchilton.blend4j.galaxy.beans.Tool) Test(org.junit.Test)

Example 9 with HistoryContentsProvenance

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

the class AnalysisProvenanceServiceGalaxyTest method testBuildSingleStepToolExecutionOneParameter.

@Test
public void testBuildSingleStepToolExecutionOneParameter() throws ExecutionManagerException {
    final HistoryContents hc = new HistoryContents();
    hc.setName(FILENAME);
    final HistoryContentsProvenance hcp = new HistoryContentsProvenance();
    hcp.setParameters(ImmutableMap.of("akey", (Object) "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"));
    assertTrue("Tool execution should be considered input step, no predecessors.", toolExecution.isInputTool());
}
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 10 with HistoryContentsProvenance

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

the class AnalysisProvenanceServiceGalaxy method buildToolExecutionForOutputFile.

/**
 * Build up a provenance report for a specific file that's attached to the
 * outputs of an analysis submission.
 *
 * @param remoteAnalysisId
 *            the identifier of the submission history that the output file
 *            is attached to on the execution manager (i.e., Galaxy's
 *            history id).
 * @param analysisOutputFilename
 *            the filename to build the report for. This should be the raw
 *            basename of the file (i.e., only the filename + extension
 *            part).
 * @return the complete report for the file.
 * @throws ExecutionManagerException
 *             if the history contents could not be shown for the specified
 *             file.
 */
public ToolExecution buildToolExecutionForOutputFile(final String remoteAnalysisId, final String analysisOutputFilename) throws ExecutionManagerException {
    final List<HistoryContents> historyContents = galaxyHistoriesService.showHistoryContents(remoteAnalysisId);
    // group the history contents by name. The names that we're interested
    // in starting from should match the filename of the output file.
    final Map<String, List<HistoryContents>> historyContentsByName = historyContents.stream().collect(Collectors.groupingBy(HistoryContents::getName));
    final List<HistoryContents> currentContents = historyContentsByName.get(analysisOutputFilename);
    if (currentContents == null || currentContents.isEmpty() || currentContents.size() > 1) {
        throw new ExecutionManagerException("Could not load a unique history contents for the specified filename [" + analysisOutputFilename + "] in history with id [" + remoteAnalysisId + "]");
    }
    final HistoryContentsProvenance currentProvenance = galaxyHistoriesService.showProvenance(remoteAnalysisId, currentContents.get(0).getId());
    try {
        final Tool toolDetails = toolsClient.showTool(currentProvenance.getToolId());
        return buildToolExecutionForHistoryStep(toolDetails, currentProvenance, remoteAnalysisId);
    } catch (final RuntimeException e) {
        throw new ExecutionManagerException("Failed to build tool execution provenance.", e);
    }
}
Also used : HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) List(java.util.List) HistoryContentsProvenance(com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance) ExecutionManagerException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException) 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