Search in sources :

Example 1 with DockerComposeCreateProject

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");
    }
}
Also used : DockerContainer(io.elastest.epm.client.json.DockerContainerInfo.DockerContainer) ArrayList(java.util.ArrayList) Parameter(io.elastest.etm.model.Parameter) SutSpecification(io.elastest.etm.model.SutSpecification) DockerComposeCreateProject(io.elastest.epm.client.json.DockerComposeCreateProject) IOException(java.io.IOException)

Aggregations

DockerComposeCreateProject (io.elastest.epm.client.json.DockerComposeCreateProject)1 DockerContainer (io.elastest.epm.client.json.DockerContainerInfo.DockerContainer)1 Parameter (io.elastest.etm.model.Parameter)1 SutSpecification (io.elastest.etm.model.SutSpecification)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1