Search in sources :

Example 6 with CommandLineElement

use of com.genericworkflownodes.knime.commandline.CommandLineElement 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 7 with CommandLineElement

use of com.genericworkflownodes.knime.commandline.CommandLineElement 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)7 CommandLineFixedString (com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString)6 ArrayList (java.util.ArrayList)6 CommandLineParameter (com.genericworkflownodes.knime.commandline.impl.CommandLineParameter)3 FileParameter (com.genericworkflownodes.knime.parameter.FileParameter)3 File (java.io.File)3 CommandLineCTDFile (com.genericworkflownodes.knime.commandline.impl.CommandLineCTDFile)2 CommandLineFile (com.genericworkflownodes.knime.commandline.impl.CommandLineFile)2 IFileParameter (com.genericworkflownodes.knime.parameter.IFileParameter)2 ListParameter (com.genericworkflownodes.knime.parameter.ListParameter)2 List (java.util.List)2 CLIElement (com.genericworkflownodes.knime.cliwrapper.CLIElement)1 CLIMapping (com.genericworkflownodes.knime.cliwrapper.CLIMapping)1 BoolParameter (com.genericworkflownodes.knime.parameter.BoolParameter)1 FileListParameter (com.genericworkflownodes.knime.parameter.FileListParameter)1 Parameter (com.genericworkflownodes.knime.parameter.Parameter)1 StringParameter (com.genericworkflownodes.knime.parameter.StringParameter)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1