Search in sources :

Example 16 with HistoryContents

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

the class AnalysisWorkspaceServiceGalaxyIT method testPrepareAnalysisFilesSingleSuccess.

/**
 * Tests out successfully preparing single workflow input files for
 * execution.
 *
 * @throws InterruptedException
 * @throws ExecutionManagerException
 * @throws IOException
 * @throws IridaWorkflowException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testPrepareAnalysisFilesSingleSuccess() throws InterruptedException, ExecutionManagerException, IOException, IridaWorkflowException {
    History history = new History();
    history.setName("testPrepareAnalysisFilesSingleSuccess");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
    LibrariesClient librariesClient = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient();
    History createdHistory = historiesClient.create(history);
    IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(validWorkflowIdSingle);
    Path workflowPath = iridaWorkflow.getWorkflowStructure().getWorkflowFile();
    String workflowString = new String(Files.readAllBytes(workflowPath), StandardCharsets.UTF_8);
    Workflow galaxyWorkflow = workflowsClient.importWorkflow(workflowString);
    AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupSubmissionInDatabase(1L, sequenceFilePathA, referenceFilePath, validWorkflowIdSingle, false);
    analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
    analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
    PreparedWorkflowGalaxy preparedWorkflow = analysisWorkspaceService.prepareAnalysisFiles(analysisSubmission);
    assertEquals("the response history id should match the input history id", createdHistory.getId(), preparedWorkflow.getRemoteAnalysisId());
    assertNotNull("the returned workflow inputs should not be null", preparedWorkflow.getWorkflowInputs());
    assertNotNull("the returned library id should not be null", preparedWorkflow.getRemoteDataId());
    // verify correct library is created
    List<LibraryContent> libraryContents = librariesClient.getLibraryContents(preparedWorkflow.getRemoteDataId());
    Map<String, List<LibraryContent>> libraryContentsMap = libraryContents.stream().collect(Collectors.groupingBy(LibraryContent::getName));
    assertFalse("the returned library should exist in Galaxy", libraryContentsMap.isEmpty());
    String sequenceFileALibraryName = "/" + sequenceFilePathA.getFileName().toString();
    assertEquals("the returned library does not contain the correct number of elements", 2, libraryContentsMap.size());
    assertTrue("the returned library does not contain a root folder", libraryContentsMap.containsKey("/"));
    assertTrue("the returned library does not contain the correct sequence file", libraryContentsMap.containsKey(sequenceFileALibraryName));
    assertEquals("the returned library does not contain the correct sequence file", 1, libraryContentsMap.get(sequenceFileALibraryName).size());
    // verify correct files have been uploaded
    List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
    assertEquals("the created history should contain 3 entries", 3, historyContents.size());
    Map<String, HistoryContents> contentsMap = historyContentsAsMap(historyContents);
    assertTrue("the created history should contain the file " + sequenceFilePathA.toFile().getName(), contentsMap.containsKey(sequenceFilePathA.toFile().getName()));
    assertTrue("the created history should contain the file " + referenceFilePath.toFile().getName(), contentsMap.containsKey(referenceFilePath.toFile().getName()));
    assertTrue("the created history should contain the collection with name " + INPUTS_SINGLE_NAME, contentsMap.containsKey(INPUTS_SINGLE_NAME));
    // make sure workflow inputs contains correct information
    Map<String, WorkflowInput> workflowInputsMap = preparedWorkflow.getWorkflowInputs().getInputsObject().getInputs();
    assertEquals("the created workflow inputs has an invalid number of elements", 2, workflowInputsMap.size());
}
Also used : Path(java.nio.file.Path) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) LibraryContent(com.github.jmchilton.blend4j.galaxy.beans.LibraryContent) Workflow(com.github.jmchilton.blend4j.galaxy.beans.Workflow) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) History(com.github.jmchilton.blend4j.galaxy.beans.History) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) WorkflowsClient(com.github.jmchilton.blend4j.galaxy.WorkflowsClient) PreparedWorkflowGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy) List(java.util.List) ArrayList(java.util.ArrayList) WorkflowInput(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs.WorkflowInput) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 17 with HistoryContents

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContents 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 18 with HistoryContents

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContents 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 19 with HistoryContents

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

the class AnalysisProvenanceServiceGalaxyTest method testShowProvenanceFailureNoFiles2.

@Test(expected = ExecutionManagerException.class)
public void testShowProvenanceFailureNoFiles2() throws ExecutionManagerException {
    final HistoryContents hc = new HistoryContents();
    hc.setName("wrong name");
    when(galaxyHistoriesService.showHistoryContents(any(String.class))).thenReturn(Lists.newArrayList(hc));
    provenanceService.buildToolExecutionForOutputFile(analysisSubmission(), analysisOutputFile());
}
Also used : HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) Test(org.junit.Test)

Example 20 with HistoryContents

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContents 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)

Aggregations

HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)22 Test (org.junit.Test)18 History (com.github.jmchilton.blend4j.galaxy.beans.History)11 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)9 HistoryContentsProvenance (com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance)8 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 Path (java.nio.file.Path)7 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)6 PreparedWorkflowGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy)6 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)6 WorkflowsClient (com.github.jmchilton.blend4j.galaxy.WorkflowsClient)6 Tool (com.github.jmchilton.blend4j.galaxy.beans.Tool)6 Workflow (com.github.jmchilton.blend4j.galaxy.beans.Workflow)6 ToolExecution (ca.corefacility.bioinformatics.irida.model.workflow.analysis.ToolExecution)5 WorkflowInputsGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy)5 JobDetails (com.github.jmchilton.blend4j.galaxy.beans.JobDetails)5 LibrariesClient (com.github.jmchilton.blend4j.galaxy.LibrariesClient)4 HashMap (java.util.HashMap)4 List (java.util.List)4 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)3