use of io.elastest.epm.client.json.DockerComposeCreateProject 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");
}
}
Aggregations