Search in sources :

Example 11 with SutSpecification

use of io.elastest.etm.model.SutSpecification 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)

Example 12 with SutSpecification

use of io.elastest.etm.model.SutSpecification in project elastest-torm by elastest.

the class TJobExecOrchestratorService method endSutInContainer.

public void endSutInContainer(DockerExecution dockerExec) throws Exception {
    SutSpecification sut = dockerExec.gettJobexec().getTjob().getSut();
    String containerName = null;
    String sutPrefix = null;
    boolean isDockerCompose = false;
    // If is Docker compose Sut
    if (sut.getCommandsOption() == CommandsOptionEnum.IN_DOCKER_COMPOSE) {
        containerName = this.getCurrentExecSutMainServiceName(sut, dockerExec);
        sutPrefix = this.dockerService.getSutPrefix(dockerExec);
        isDockerCompose = true;
    } else // If is unique Docker image Sut
    if (sut.getCommandsOption() == CommandsOptionEnum.IN_NEW_CONTAINER) {
        containerName = dockerService.getSutPrefix(dockerExec);
        sutPrefix = containerName;
    }
    // Add containers to dockerService list
    if (isDockerCompose) {
        List<Container> containersList = this.dockerService.getContainersCreatedSinceId(dockerExec.getAppContainerId());
        this.dockerService.getContainersByNamePrefixByGivenList(containersList, sutPrefix, ContainersListActionEnum.REMOVE);
    } else {
        this.dockerService.endContainer(containerName);
    }
}
Also used : Container(com.github.dockerjava.api.model.Container) DockerContainer(io.elastest.epm.client.json.DockerContainerInfo.DockerContainer) SutSpecification(io.elastest.etm.model.SutSpecification)

Example 13 with SutSpecification

use of io.elastest.etm.model.SutSpecification in project elastest-torm by elastest.

the class TJobExecOrchestratorService method startManagedSut.

private SutExecution startManagedSut(DockerExecution dockerExec) throws Exception {
    TJobExecution tJobExec = dockerExec.gettJobexec();
    SutSpecification sut = dockerExec.gettJobexec().getTjob().getSut();
    String resultMsg = "Executing dockerized SuT";
    updateTJobExecResultStatus(tJobExec, TJobExecution.ResultEnum.EXECUTING_SUT, resultMsg);
    logger.info(resultMsg + " " + dockerExec.getExecutionId());
    SutExecution sutExec = sutService.createSutExecutionBySut(sut);
    try {
        // By Docker Image
        if (sut.getManagedDockerType() != ManagedDockerType.COMPOSE) {
            startSutByDockerImage(dockerExec);
        } else // By Docker Compose
        {
            startSutByDockerCompose(dockerExec);
        }
        sutExec.setDeployStatus(SutExecution.DeployStatusEnum.DEPLOYED);
        String sutContainerId = dockerExec.getAppContainerId();
        String sutIP = dockerService.getContainerIpWithDockerExecution(sutContainerId, dockerExec);
        // If port is defined, wait for SuT ready
        if (sut.getPort() != null) {
            String sutPort = sut.getPort();
            resultMsg = "Waiting for SuT service ready in port " + sutPort;
            logger.info(resultMsg);
            updateTJobExecResultStatus(tJobExec, TJobExecution.ResultEnum.WAITING_SUT, resultMsg);
            // If is Sut In new Container
            if (sut.isSutInNewContainer()) {
                // 8min
                sutIP = this.waitForSutInContainer(dockerExec, 480000);
            }
            // Wait for SuT started
            dockerService.checkSut(dockerExec, sutIP, sutPort);
            endCheckSutExec(dockerExec);
        }
        // Save SuTUrl and Ip into sutexec
        String sutUrl = "http://" + sutIP + ":" + (sut.getPort() != null ? sut.getPort() : "");
        sutExec.setUrl(sutUrl);
        sutExec.setIp(sutIP);
    } catch (TJobStoppedException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Exception during TJob execution", e);
        sutExec.setDeployStatus(SutExecution.DeployStatusEnum.ERROR);
        try {
            sutService.modifySutExec(dockerExec.getSutExec());
        } catch (Exception e1) {
        }
        throw e;
    }
    return sutExec;
}
Also used : TJobExecution(io.elastest.etm.model.TJobExecution) SutExecution(io.elastest.etm.model.SutExecution) SutSpecification(io.elastest.etm.model.SutSpecification) IOException(java.io.IOException)

Example 14 with SutSpecification

use of io.elastest.etm.model.SutSpecification in project elastest-torm by elastest.

the class TJobExecOrchestratorService method waitForSutInContainer.

public String waitForSutInContainer(DockerExecution dockerExec, long timeout) throws Exception {
    SutSpecification sut = dockerExec.gettJobexec().getTjob().getSut();
    String containerName = null;
    String sutPrefix = null;
    boolean isDockerCompose = false;
    // If is Docker compose Sut
    if (sut.getCommandsOption() == CommandsOptionEnum.IN_DOCKER_COMPOSE) {
        containerName = this.getCurrentExecSutMainServiceName(sut, dockerExec);
        sutPrefix = this.dockerService.getSutPrefix(dockerExec);
        isDockerCompose = true;
    } else // If is unique Docker image Sut
    if (sut.getCommandsOption() == CommandsOptionEnum.IN_NEW_CONTAINER) {
        containerName = dockerService.getSutPrefix(dockerExec);
        sutPrefix = containerName;
    }
    // Wait for created
    this.dockerService.waitForContainerCreated(containerName, dockerExec, timeout);
    // Insert main sut/service into ET network
    this.dockerService.insertIntoNetwork(dockerExec.getNetwork(), this.dockerService.getContainerIdByName(containerName));
    // Get Main sut/service ip from ET network
    String sutIp = dockerService.waitForContainerIpWithDockerExecution(containerName, dockerExec, timeout);
    // Add containers to dockerService list
    if (isDockerCompose) {
        List<Container> containersList = this.dockerService.getContainersCreatedSinceId(dockerExec.getAppContainerId());
        this.dockerService.getContainersByNamePrefixByGivenList(containersList, sutPrefix, ContainersListActionEnum.ADD);
    } else {
        String containerId = this.dockerService.getContainerIdByName(containerName);
        this.dockerService.insertCreatedContainer(containerId, containerName);
    }
    return sutIp;
}
Also used : Container(com.github.dockerjava.api.model.Container) DockerContainer(io.elastest.epm.client.json.DockerContainerInfo.DockerContainer) SutSpecification(io.elastest.etm.model.SutSpecification)

Example 15 with SutSpecification

use of io.elastest.etm.model.SutSpecification in project elastest-torm by elastest.

the class SutService method createSutExecutionById.

public SutExecution createSutExecutionById(Long sutId) {
    SutSpecification sut = sutRepository.findOne(sutId);
    SutExecution sutExecution = new SutExecution();
    sutExecution.setSutSpecification(sut);
    return sutExecutionRepository.save(sutExecution);
}
Also used : SutExecution(io.elastest.etm.model.SutExecution) SutSpecification(io.elastest.etm.model.SutSpecification)

Aggregations

SutSpecification (io.elastest.etm.model.SutSpecification)23 SutExecution (io.elastest.etm.model.SutExecution)9 Test (org.junit.jupiter.api.Test)7 TJob (io.elastest.etm.model.TJob)4 TJobExecution (io.elastest.etm.model.TJobExecution)4 ArrayList (java.util.ArrayList)4 DockerContainer (io.elastest.epm.client.json.DockerContainerInfo.DockerContainer)3 Parameter (io.elastest.etm.model.Parameter)3 IOException (java.io.IOException)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 HttpEntity (org.springframework.http.HttpEntity)3 HttpHeaders (org.springframework.http.HttpHeaders)3 Container (com.github.dockerjava.api.model.Container)2 Project (io.elastest.etm.model.Project)2 CreateContainerCmd (com.github.dockerjava.api.command.CreateContainerCmd)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 Bind (com.github.dockerjava.api.model.Bind)1