Search in sources :

Example 1 with CommandLineFixedString

use of com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString in project GenericKnimeNodes by genericworkflownodes.

the class DockerCommandGenerator method handleFileParameter.

/**
 * Process a file parameter by specifying the docker mount point and
 * altering the file paths to fit the internal docker path
 *
 * @param hostFile string to file on host system
 * @param dockerCommands a list of specific docker commands
 * @param hostDockerMap a map of host paths to docker paths that have already been mapped
 * @return List of extracted commands
 * @throws IOException
 */
private List<? extends CommandLineElement> handleFileParameter(String hostFile, List<CommandLineElement> dockerCommands, Map<String, String> hostDockerMap) throws IOException {
    String dockerMount;
    File fileParam = new File(hostFile);
    String hostPath = toUnixPath(fileParam.getParentFile().getCanonicalPath());
    if (hostDockerMap.containsKey(hostPath)) {
        dockerMount = hostDockerMap.get(hostPath);
    } else {
        dockerMount = DOCKER_INTERNAL_MOUNT + dockerCommands.size() + DOCKER_DIR_SEP;
        hostDockerMap.put(hostPath, dockerMount);
        dockerCommands.add(new CommandLineFixedString(DOCKER_MOUNT_COMMAND));
        dockerCommands.add(new CommandLineFixedString(hostPath + ":" + dockerMount));
    }
    List<CommandLineElement> l = new ArrayList<CommandLineElement>();
    l.add(new CommandLineFixedString(dockerMount + fileParam.getName()));
    return l;
}
Also used : ArrayList(java.util.ArrayList) CommandLineFixedString(com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString) CommandLineFixedString(com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString) CommandLineElement(com.genericworkflownodes.knime.commandline.CommandLineElement) File(java.io.File)

Example 2 with CommandLineFixedString

use of com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString in project GenericKnimeNodes by genericworkflownodes.

the class BALLCommandGenerator method generateCommands.

@Override
public List<CommandLineElement> generateCommands(INodeConfiguration nodeConfiguration, IPluginConfiguration pluginConfiguration, File workingDirectory) throws Exception {
    File paramFile = writePARFile(nodeConfiguration, workingDirectory);
    List<CommandLineElement> commands = new ArrayList<CommandLineElement>();
    commands.add(new CommandLineFixedString(PAR_SWITCH));
    commands.add(new CommandLineCTDFile(paramFile));
    return commands;
}
Also used : CommandLineCTDFile(com.genericworkflownodes.knime.commandline.impl.CommandLineCTDFile) ArrayList(java.util.ArrayList) CommandLineFixedString(com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString) CommandLineElement(com.genericworkflownodes.knime.commandline.CommandLineElement) CommandLineCTDFile(com.genericworkflownodes.knime.commandline.impl.CommandLineCTDFile) File(java.io.File)

Example 3 with CommandLineFixedString

use of com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString in project GenericKnimeNodes by genericworkflownodes.

the class OpenMSCommandGenerator method generateCommands.

@Override
public List<CommandLineElement> generateCommands(INodeConfiguration nodeConfiguration, IPluginConfiguration pluginConfiguration, File workingDirectory) throws Exception {
    File iniFile = createINIFile(nodeConfiguration, workingDirectory);
    List<CommandLineElement> commands = new ArrayList<CommandLineElement>();
    commands.add(new CommandLineFixedString(INI_SWITCH));
    commands.add(new CommandLineCTDFile(iniFile));
    return commands;
}
Also used : CommandLineCTDFile(com.genericworkflownodes.knime.commandline.impl.CommandLineCTDFile) ArrayList(java.util.ArrayList) CommandLineFixedString(com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString) CommandLineElement(com.genericworkflownodes.knime.commandline.CommandLineElement) CommandLineCTDFile(com.genericworkflownodes.knime.commandline.impl.CommandLineCTDFile) File(java.io.File)

Example 4 with CommandLineFixedString

use of com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString in project GenericKnimeNodes by genericworkflownodes.

the class DockerCommandGenerator method processCLI.

/**
 * Converts the CLI part of the configuration to a list of commands that can
 * be send to the shell.
 *
 * @return A configured list of commands.
 * @throws Exception
 *             Is thrown if the configuration values are invalid.
 */
protected List<CommandLineElement> processCLI() throws Exception {
    List<CommandLineElement> commands = new ArrayList<CommandLineElement>();
    List<CommandLineElement> dockerCommands = new ArrayList<CommandLineElement>();
    Map<String, String> hostDockerMap = new HashMap<String, String>();
    dockerCommands.add(new CommandLineFixedString(GenericNodesPlugin.getDockerInstallationDir() + File.separator + DOCKER_COMMAND));
    dockerCommands.add(new CommandLineFixedString(DOCKER_EXECUTION));
    // this DOES NOT represent the docker VM, rather, the name of the executable
    // INSIDE the docker image, so it's always fixed!
    commands.add(new CommandLineFixedString(nodeConfig.getExecutablePath() + nodeConfig.getExecutableName()));
    for (CLIElement cliElement : nodeConfig.getCLI().getCLIElement()) {
        logger.info("CLIElement: " + cliElement.getOptionIdentifier());
        if (!"".equals(cliElement.getOptionIdentifier()) && cliElement.getMapping().size() == 0) {
            // simple fixed argument for the command line, no mapping to
            // params given
            // to avoid problems with spaces in commands we split fixed
            // values
            String[] splitResult = cliElement.getOptionIdentifier().split(" ");
            for (String splittedCommand : splitResult) {
                commands.add(new CommandLineFixedString(splittedCommand));
            }
        } else if (super.isMappedToBooleanParameter(cliElement)) {
            // it is mapped to bool
            super.handleBooleanParameter(commands, cliElement);
        } else {
            List<List<? extends CommandLineElement>> extractedParameterValues = extractParamterValues(cliElement, dockerCommands, hostDockerMap);
            validateExtractedParameters(extractedParameterValues);
            // were not set
            if (extractedParameterValues.size() != 0) {
                expandParameters(extractedParameterValues, cliElement, commands);
            }
        }
    }
    try {
        String dockerContainer = pluginConfig.getToolProperty(nodeConfig.getName()).getProperty("dockerImage", null);
        dockerCommands.add(new CommandLineFixedString(dockerContainer.replace("\"", "")));
        dockerCommands.addAll(commands);
        return dockerCommands;
    } catch (NullPointerException e) {
        throw new Exception(String.format("Docker-Node %s has no image defined", nodeConfig.getName()));
    }
}
Also used : HashMap(java.util.HashMap) CLIElement(com.genericworkflownodes.knime.cliwrapper.CLIElement) ArrayList(java.util.ArrayList) CommandLineFixedString(com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString) ArrayList(java.util.ArrayList) List(java.util.List) CommandLineElement(com.genericworkflownodes.knime.commandline.CommandLineElement) CommandLineFixedString(com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString) IOException(java.io.IOException)

Example 5 with CommandLineFixedString

use of com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString in project GenericKnimeNodes by genericworkflownodes.

the class DockerCommandGenerator method extractParamterValues.

private List<List<? extends CommandLineElement>> extractParamterValues(CLIElement cliElement, List<CommandLineElement> dockerCommands, Map<String, String> hostDockerMap) throws IOException {
    List<List<? extends CommandLineElement>> extractedParameterValues = new ArrayList<List<? extends CommandLineElement>>();
    for (CLIMapping cliMapping : cliElement.getMapping()) {
        if (nodeConfig.getParameterKeys().contains(cliMapping.getReferenceName())) {
            Parameter<?> p = nodeConfig.getParameter(cliMapping.getReferenceName());
            if (!p.isNull()) {
                if (p instanceof ListParameter) {
                    ListParameter lp = (ListParameter) p;
                    if (lp.getStrings().size() > 0) {
                        final List<CommandLineElement> tmp = new ArrayList<CommandLineElement>();
                        for (final String s : lp.getStrings()) {
                            tmp.add(new CommandLineFixedString(s));
                        }
                        extractedParameterValues.add(tmp);
                    }
                } else if (p instanceof FileParameter) {
                    extractedParameterValues.add(handleFileParameter(((FileParameter) p).getValue(), dockerCommands, hostDockerMap));
                } else if (p instanceof FileListParameter) {
                    List<String> fl = ((FileListParameter) p).getValue();
                    if (fl.size() > 0) {
                        for (String hostFile : fl) {
                            extractedParameterValues.add(handleFileParameter(hostFile, dockerCommands, hostDockerMap));
                        }
                    }
                } else {
                    List<CommandLineElement> l = new ArrayList<CommandLineElement>();
                    l.add(new CommandLineParameter(p));
                    extractedParameterValues.add(l);
                }
            }
        }
    }
    return extractedParameterValues;
}
Also used : FileListParameter(com.genericworkflownodes.knime.parameter.FileListParameter) CommandLineParameter(com.genericworkflownodes.knime.commandline.impl.CommandLineParameter) ArrayList(java.util.ArrayList) CLIMapping(com.genericworkflownodes.knime.cliwrapper.CLIMapping) CommandLineElement(com.genericworkflownodes.knime.commandline.CommandLineElement) CommandLineFixedString(com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString) CommandLineFixedString(com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString) ArrayList(java.util.ArrayList) List(java.util.List) FileParameter(com.genericworkflownodes.knime.parameter.FileParameter) FileListParameter(com.genericworkflownodes.knime.parameter.FileListParameter) ListParameter(com.genericworkflownodes.knime.parameter.ListParameter)

Aggregations

CommandLineElement (com.genericworkflownodes.knime.commandline.CommandLineElement)5 CommandLineFixedString (com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString)5 ArrayList (java.util.ArrayList)5 File (java.io.File)3 CommandLineCTDFile (com.genericworkflownodes.knime.commandline.impl.CommandLineCTDFile)2 List (java.util.List)2 CLIElement (com.genericworkflownodes.knime.cliwrapper.CLIElement)1 CLIMapping (com.genericworkflownodes.knime.cliwrapper.CLIMapping)1 CommandLineParameter (com.genericworkflownodes.knime.commandline.impl.CommandLineParameter)1 FileListParameter (com.genericworkflownodes.knime.parameter.FileListParameter)1 FileParameter (com.genericworkflownodes.knime.parameter.FileParameter)1 ListParameter (com.genericworkflownodes.knime.parameter.ListParameter)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1