Search in sources :

Example 1 with SocatBindedPort

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SocatBindedPort(io.elastest.etm.model.SocatBindedPort) IOException(java.io.IOException)

Example 2 with SocatBindedPort

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");
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) TestLinkAPIException(br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException) SocatBindedPort(io.elastest.etm.model.SocatBindedPort) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) MalformedURLException(java.net.MalformedURLException) TestLinkAPIException(br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException) URL(java.net.URL) TestLinkAPI(br.eti.kinoshita.testlinkjavaapi.TestLinkAPI) PostConstruct(javax.annotation.PostConstruct)

Example 3 with SocatBindedPort

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;
}
Also used : ExposedPort(com.github.dockerjava.api.model.ExposedPort) DockerClient(com.github.dockerjava.api.DockerClient) ArrayList(java.util.ArrayList) Ports(com.github.dockerjava.api.model.Ports) SocatBindedPort(io.elastest.etm.model.SocatBindedPort) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotModifiedException(com.github.dockerjava.api.exception.NotModifiedException) DockerClientException(com.github.dockerjava.api.exception.DockerClientException) InternalServerErrorException(com.github.dockerjava.api.exception.InternalServerErrorException) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

SocatBindedPort (io.elastest.etm.model.SocatBindedPort)3 IOException (java.io.IOException)2 TestLinkAPI (br.eti.kinoshita.testlinkjavaapi.TestLinkAPI)1 TestLinkAPIException (br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 DockerClient (com.github.dockerjava.api.DockerClient)1 DockerClientException (com.github.dockerjava.api.exception.DockerClientException)1 InternalServerErrorException (com.github.dockerjava.api.exception.InternalServerErrorException)1 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)1 NotModifiedException (com.github.dockerjava.api.exception.NotModifiedException)1 ExposedPort (com.github.dockerjava.api.model.ExposedPort)1 Ports (com.github.dockerjava.api.model.Ports)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 PostConstruct (javax.annotation.PostConstruct)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1 SAXException (org.xml.sax.SAXException)1