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