use of io.elastest.epm.client.json.DockerContainerInfo.DockerContainer in project elastest-torm by elastest.
the class TJobExecOrchestratorService method startSutByDockerCompose.
public void startSutByDockerCompose(DockerExecution dockerExec) throws Exception {
SutSpecification sut = dockerExec.gettJobexec().getTjob().getSut();
String mainService = sut.getMainService();
String composeProjectName = dockerService.getSutName(dockerExec);
// Because docker-compose-ui api removes underscores '_'
String containerPrefix = composeProjectName.replaceAll("_", "");
// TMP replace sut exec and logstash sut tcp
String dockerComposeYml = sut.getSpecification();
dockerComposeYml = setElasTestConfigToDockerComposeYml(dockerComposeYml, composeProjectName, dockerExec);
// Environment variables (optional)
ArrayList<String> envList = new ArrayList<>();
String envVar;
// Get Parameters and insert into Env Vars
for (Parameter parameter : sut.getParameters()) {
envVar = parameter.getName() + "=" + parameter.getValue();
envList.add(envVar);
}
DockerComposeCreateProject project = new DockerComposeCreateProject(composeProjectName, dockerComposeYml, envList);
// Create Containers
boolean created = dockerComposeService.createProject(project);
// Start Containers
if (!created) {
throw new Exception("Sut docker compose containers are not created");
}
dockerComposeService.startProject(composeProjectName);
for (DockerContainer container : dockerComposeService.getContainers(composeProjectName).getContainers()) {
String containerId = dockerService.getContainerIdByName(container.getName());
// Insert container into containers list
dockerService.insertCreatedContainer(containerId, container.getName());
// If is main service container, set app id
if (container.getName().equals(containerPrefix + "_" + mainService + "_1")) {
dockerExec.setAppContainerId(containerId);
}
}
if (dockerExec.getAppContainerId() == null || dockerExec.getAppContainerId().isEmpty()) {
throw new Exception("Main Sut service from docker compose not started");
}
}
use of io.elastest.epm.client.json.DockerContainerInfo.DockerContainer in project elastest-torm by elastest.
the class TestEnginesService method getServiceUrl.
public String getServiceUrl(String serviceName) {
String url = "";
try {
for (DockerContainer container : dockerComposeService.getContainers(serviceName).getContainers()) {
log.debug("Container info: {}", container);
// example:
String containerName = serviceName + "_" + serviceName + "_1";
// ece_ece_1
if (container.getName().equals(containerName)) {
String ip = etPublicHost;
String port = "";
for (Entry<String, List<PortInfo>> portList : container.getPorts().entrySet()) {
if (portList.getValue() != null) {
if (ip.equals("localhost")) {
port = portList.getKey().split("/")[0];
ip = dockerService2.getContainerIpByNetwork(containerName, network);
} else {
port = portList.getValue().get(0).getHostPort();
}
break;
}
}
if ("".equals(port)) {
throw new Exception("Port not found");
}
url = "http://" + ip + ":" + port;
if (serviceName.equals("ere")) {
url += "/ere-app";
}
log.debug("Url: " + url);
}
}
} catch (Exception e) {
log.error("Service url not exist {}", serviceName, e);
}
return url;
}
Aggregations