use of io.elastest.etm.model.SocatBindedPort in project elastest-torm by elastest.
the class EsmService method getEndpointsInfo.
private SupportServiceInstance getEndpointsInfo(SupportServiceInstance serviceInstance, JsonNode node, String tSSContainerName, String networkName, String nodeName) throws Exception {
int auxPort = 37000;
if (node != null) {
if (!etPublicHost.equals("localhost")) {
if (node.get("port") != null) {
String nodePort = node.get("port").toString().replaceAll("\"", "");
if (serviceInstance.getEndpointsBindingsPorts().containsKey(nodePort)) {
auxPort = Integer.parseInt(serviceInstance.getEndpointsBindingsPorts().get(nodePort));
} else {
try {
SocatBindedPort socatBindedPortObj = dockerService.bindingPort(serviceInstance.getContainerIp(), node.get("port").toString(), networkName);
serviceInstance.getPortBindingContainers().add(socatBindedPortObj.getBindedPort());
auxPort = Integer.parseInt(socatBindedPortObj.getListenPort());
serviceInstance.getEndpointsBindingsPorts().put(nodePort, String.valueOf(auxPort));
} catch (Exception e) {
logger.error("Ports binding fails: {} ", e.getMessage());
throw new Exception("Ports binding fails: " + e.getMessage());
}
}
}
((ObjectNode) node).put("port", auxPort);
if (node.get("protocol") != null && (node.get("protocol").toString().contains("http")) || node.get("protocol").toString().contains("ws")) {
serviceInstance.setServicePort(auxPort);
serviceInstance.getUrls().put(nodeName, createServiceInstanceUrl(node, serviceInstance.getServiceIp()));
}
} else if (node.get("port") != null && node.get("protocol") != null && (node.get("protocol").toString().contains("http")) || node.get("protocol").toString().contains("ws")) {
serviceInstance.setServicePort(Integer.parseInt(node.get("port").toString().replaceAll("\"", "")));
serviceInstance.getUrls().put(nodeName, createServiceInstanceUrl(node, serviceInstance.getServiceIp()));
}
serviceInstance.getEndpointsData().put(nodeName, node);
}
return serviceInstance;
}
use of io.elastest.etm.model.SocatBindedPort in project elastest-torm by elastest.
the class TestLinkService method init.
@PostConstruct
public void init() {
if (!etEtmTestLinkHost.equals("none")) {
if (etEtmTestLinkServiceName.equals(etEtmTestLinkHost)) {
etEtmTestLinkHost = etEtmTestLinkContainerName;
}
try {
// Default development
this.testLinkHost = this.dockerService.getContainerIpByNetwork(etEtmTestLinkHost, etDockerNetwork);
this.testLinkPort = etEtmTestLinkPort;
// If not development, start socat
if (!etPublicHost.equals("localhost")) {
try {
String testLinkIp = UtilTools.doPing(etEtmTestLinkHost);
logger.info("Real TestLink Ip: {}", testLinkIp);
SocatBindedPort socatBindedPort = dockerService.bindingPort(testLinkIp, etEtmTestLinkPort, etDockerNetwork);
this.testLinkHost = etPublicHost;
this.testLinkPort = socatBindedPort.getListenPort();
} catch (Exception e) {
logger.error("Cannot get Testlink socat data", e);
this.testLinkHost = etEtmTestLinkHost;
this.testLinkPort = etEtmTestLinkPort;
}
}
String url = this.getTestLinkUrl() + "/lib/api/xmlrpc/v1/xmlrpc.php";
try {
testlinkURL = new URL(url);
} catch (MalformedURLException mue) {
mue.printStackTrace();
}
try {
api = new TestLinkAPI(testlinkURL, devKey);
} catch (TestLinkAPIException te) {
logger.error(te.getMessage());
}
} catch (Exception e) {
logger.error("Cannot get TestLink container ip");
}
}
}
use of io.elastest.etm.model.SocatBindedPort in project elastest-torm by elastest.
the class DockerService2 method bindingPort.
public SocatBindedPort bindingPort(String containerIp, String port, String networkName) throws Exception {
DockerClient dockerClient = this.getDockerClient();
int listenPort = 37000;
String bindedPort = null;
try {
listenPort = utilTools.findRandomOpenPort();
List<String> envVariables = new ArrayList<>();
envVariables.add("LISTEN_PORT=" + listenPort);
envVariables.add("FORWARD_PORT=" + port);
envVariables.add("TARGET_SERVICE_IP=" + containerIp);
Ports portBindings = new Ports();
ExposedPort exposedListenPort = ExposedPort.tcp(listenPort);
portBindings.bind(exposedListenPort, Ports.Binding.bindPort(listenPort));
bindedPort = this.runDockerContainer(dockerClient, etSocatImage, envVariables, "container" + listenPort, networkName, portBindings, listenPort);
} catch (Exception e) {
e.printStackTrace();
throw new Exception(e.getMessage());
}
SocatBindedPort bindedPortObj = new SocatBindedPort(Integer.toString(listenPort), bindedPort);
return bindedPortObj;
}
Aggregations