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()));
}
}
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;
}
Aggregations