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");
}
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations