+ VIRTUALBOX_NODE_NAME_SEPARATOR + "\"");
String vmName = VIRTUALBOX_IMAGE_PREFIX + key.getId();
IMachine masterMachine;
Master master;
// ready the preseed file server
PreseedCfgServer server = new PreseedCfgServer();
try {
// try and find a master machine in vbox
masterMachine = manager.get().getVBox().findMachine(vmName);
master = Master.builder().machine(masterMachine).build();
} catch (VBoxException e) {
if (machineNotFoundException(e)) {
// machine was not found try to build one from a yaml file
YamlImage currentImage = checkNotNull(imageMapping.get(key.getId()), "currentImage");
URI preseedServer;
try {
preseedServer = new URI(preconfigurationUrl);
if (!socketTester.apply(HostAndPort.fromParts(preseedServer.getHost(), preseedServer.getPort()))) {
server.start(preconfigurationUrl, currentImage.preseed_cfg);
}
} catch (URISyntaxException e1) {
logger.error("Cannot start the preseed server", e);
throw e;
}
MasterSpec masterSpec = buildMasterSpecFromYaml(currentImage, vmName);
masterMachine = masterCreatorAndInstaller.apply(masterSpec);
master = Master.builder().machine(masterMachine).spec(masterSpec).build();
} else {
logger.error("Problem during master creation", e);
throw e;
}
} finally {
server.stop();
}
masters.put(key.getId(), master);
return master;
}