Search in sources :

Example 1 with JobDetails

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

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

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

the class JobDetailsCommandLineTransfer method main.

public static void main(String[] args) {
    checkNotNull(GALAXY_URL, "Galaxy URL is required. [galaxy.url]");
    checkNotNull(GALAXY_API, "Galaxy API key is required. [galaxy.api.key]");
    checkNotNull(JDBC_URL, "JDBC URL is required. [jdbc.url]");
    checkNotNull(JDBC_USER, "JDBC user is required. [jdbc.user]");
    checkNotNull(JDBC_PASS, "JDBC password is required. [jdbc.pass]");
    final GalaxyInstance gi = GalaxyInstanceFactory.get(GALAXY_URL, GALAXY_API);
    final JobsClient jobsClient = gi.getJobsClient();
    final DriverManagerDataSource dataSource = new DriverManagerDataSource(JDBC_URL, JDBC_USER, JDBC_PASS);
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    final JdbcTemplate template = new JdbcTemplate(dataSource);
    template.query("select id, execution_manager_identifier from tool_execution", (rs, row) -> Pair.of(rs.getLong("id"), rs.getString("execution_manager_identifier"))).forEach(e -> {
        final JobDetails jobDetails = jobsClient.showJob(e.v);
        template.update("update tool_execution set command_line = ? where id = ?", jobDetails.getCommandLine(), e.k);
        logger.debug(String.format("Updated tool execution [%s] with command line [%s]", e.k, jobDetails.getCommandLine()));
    });
}
Also used : Logger(org.slf4j.Logger) GalaxyInstance(com.github.jmchilton.blend4j.galaxy.GalaxyInstance) LoggerFactory(org.slf4j.LoggerFactory) GalaxyInstanceFactory(com.github.jmchilton.blend4j.galaxy.GalaxyInstanceFactory) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Preconditions(com.google.common.base.Preconditions) JobsClient(com.github.jmchilton.blend4j.galaxy.JobsClient) JobDetails(com.github.jmchilton.blend4j.galaxy.beans.JobDetails) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) GalaxyInstance(com.github.jmchilton.blend4j.galaxy.GalaxyInstance) JobDetails(com.github.jmchilton.blend4j.galaxy.beans.JobDetails) JobsClient(com.github.jmchilton.blend4j.galaxy.JobsClient)

Example 4 with JobDetails

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

Example 5 with JobDetails

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

Aggregations

JobDetails (com.github.jmchilton.blend4j.galaxy.beans.JobDetails)8 HistoryContentsProvenance (com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance)7 Tool (com.github.jmchilton.blend4j.galaxy.beans.Tool)7 ToolExecution (ca.corefacility.bioinformatics.irida.model.workflow.analysis.ToolExecution)6 HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)6 Test (org.junit.Test)5 JobsClient (com.github.jmchilton.blend4j.galaxy.JobsClient)3 ToolsClient (com.github.jmchilton.blend4j.galaxy.ToolsClient)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ExecutionManagerException (ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)1 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 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)1 GalaxyHistoriesService (ca.corefacility.bioinformatics.irida.pipeline.upload.galaxy.GalaxyHistoriesService)1