Commit a76fe772 authored by Unai Perez's avatar Unai Perez
Browse files

Updated LXCStarter to support hostnames in addition to IPs

parent c3109232
......@@ -134,11 +134,8 @@ public abstract class ContainerStarter extends Starter {
LOGGER.debug("[ContainerStarter] Container starter for " + name + " registers in the hashmap");
}
String containerId = "";
// String [] cmd = getStartCommand(minPort, masterName);
// LOGGER.info("Starting container with command: " + String.join(" ", cmd));
NIONode n = this.distribute(masterName, minPort, maxPort);
try {
Thread.sleep(1500);
} catch (Exception e) {
......
......@@ -6,12 +6,16 @@ import es.bsc.compss.nio.master.NIOWorkerNode;
import es.bsc.compss.nio.master.handlers.ProcessOut;
import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
// TODO: The class should use the REST API if possible, instead of relying on the script
public class LXCStarter extends ContainerStarter {
private static final String LXC_SCRIPT_PATH = System.getenv("COMPSS_HOME") + File.separator + "Runtime"
......@@ -41,6 +45,7 @@ public class LXCStarter extends ContainerStarter {
@Override
protected String[] getStopCommand(int pid) {
// TODO: This should not be using the command
return new String[] { "lxc",
"stop",
this.containerId };
......@@ -67,7 +72,17 @@ public class LXCStarter extends ContainerStarter {
cmd.add("localhost");
}
cmd.add("--worker");
cmd.add(this.nw.getName());
if (this.nameIsIp()) {
cmd.add(this.nw.getName());
} else {
try {
InetAddress address = InetAddress.getByName(this.nw.getName());
cmd.add(address.getHostAddress());
} catch (UnknownHostException e) {
throw new InitNodeException(
"Worker name is a hostname instead of an IP, and the name could not be resolved. LXC only works with IPs");
}
}
cmd.add("--storage");
cmd.add("compss:compss:/tmp/COMPSsWorker");
cmd.add("--as-public-server");
......@@ -100,4 +115,12 @@ public class LXCStarter extends ContainerStarter {
// return containerId;
return new NIONode(this.nw.getName(), Integer.parseInt(output[output.length - 1]));
}
private boolean nameIsIp() {
final Pattern pattern =
Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
return pattern.matcher(this.nw.getName()).matches();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment