Search in sources :

Example 1 with SutSpecification

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

the class TJobExecOrchestratorService method initSut.

/**
 *******************
 */
/**
 ** SuT Methods ***
 */
/**
 * @throws Exception
 *******************
 */
public void initSut(DockerExecution dockerExec) throws Exception {
    SutSpecification sut = dockerExec.gettJobexec().getTjob().getSut();
    SutExecution sutExec;
    String sutIP = "";
    // If it's MANAGED SuT
    if (sut.getSutType() != SutTypeEnum.DEPLOYED) {
        try {
            sutExec = startManagedSut(dockerExec);
        } catch (TJobStoppedException e) {
            throw e;
        }
    } else // If it's DEPLOYED SuT
    {
        Long currentSutExecId = sut.getCurrentSutExec();
        sutExec = sutService.getSutExecutionById(currentSutExecId);
        sutIP = sut.getSpecification();
        String sutUrl = "http://" + sutIP + ":" + (sut.getPort() != null ? sut.getPort() : "");
        sutExec.setUrl(sutUrl);
        sutExec.setIp(sutIP);
    }
    dockerExec.setSutExec(sutExec);
}
Also used : SutExecution(io.elastest.etm.model.SutExecution) SutSpecification(io.elastest.etm.model.SutSpecification)

Example 2 with SutSpecification

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

the class TJobExecOrchestratorService method endSutExec.

public void endSutExec(DockerExecution dockerExec) throws Exception {
    SutSpecification sut = dockerExec.gettJobexec().getTjob().getSut();
    dockerService.removeSutVolumeFolder(dockerExec);
    // If it's Managed Sut, and container is created
    if (sut.getSutType() != SutTypeEnum.DEPLOYED) {
        updateSutExecDeployStatus(dockerExec, DeployStatusEnum.UNDEPLOYING);
        if (sut.getManagedDockerType() != ManagedDockerType.COMPOSE) {
            if (sut.isSutInNewContainer()) {
                endSutInContainer(dockerExec);
            }
            dockerService.endContainer(dockerService.getSutName(dockerExec));
        } else {
            endComposedSutExec(dockerExec);
        }
        updateSutExecDeployStatus(dockerExec, DeployStatusEnum.UNDEPLOYED);
    } else {
        logger.info("SuT not ended by ElasTest -> Deployed SuT");
    }
    endCheckSutExec(dockerExec);
}
Also used : SutSpecification(io.elastest.etm.model.SutSpecification)

Example 3 with SutSpecification

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

the class DockerService2 method createContainer.

public CreateContainerResponse createContainer(DockerExecution dockerExec, String type) throws TJobStoppedException {
    TJobExecution tJobExec = dockerExec.gettJobexec();
    TJob tJob = tJobExec.getTjob();
    SutSpecification sut = tJob.getSut();
    String image = "";
    String commands = null;
    List<Parameter> parametersList = new ArrayList<Parameter>();
    String prefix = "";
    String suffix = "";
    String containerName = "";
    int logPort = 5000;
    String sutHost = null;
    String sutPath = null;
    if ("sut".equals(type.toLowerCase())) {
        parametersList = sut.getParameters();
        commands = sut.getCommands();
        image = sut.getSpecification();
        prefix = "sut_";
        if (sut.isSutInNewContainer()) {
            suffix = sut.getSutInContainerAuxLabel();
        }
        containerName = getSutName(dockerExec);
        sutPath = filesService.buildFilesPath(tJobExec, ElastestConstants.SUT_FOLDER);
        filesService.createExecFilesFolder(sutPath);
    } else if ("tjob".equals(type.toLowerCase())) {
        parametersList = tJobExec.getParameters();
        commands = tJob.getCommands();
        image = tJob.getImageName();
        prefix = "test_";
        containerName = getTestName(dockerExec);
        if (dockerExec.isWithSut()) {
            sutHost = dockerExec.getSutExec().getIp();
        }
    }
    // Environment variables (optional)
    ArrayList<String> envList = new ArrayList<>();
    String envVar;
    // Get TJob Exec Env Vars
    for (Map.Entry<String, String> entry : dockerExec.gettJobexec().getEnvVars().entrySet()) {
        envVar = entry.getKey() + "=" + entry.getValue();
        envList.add(envVar);
    }
    // Get Parameters and insert into Env Vars
    for (Parameter parameter : parametersList) {
        envVar = parameter.getName() + "=" + parameter.getValue();
        envList.add(envVar);
    }
    if (sutHost != null) {
        envList.add("ET_SUT_HOST=" + dockerExec.getSutExec().getIp());
    }
    // Commands (optional)
    ArrayList<String> cmdList = new ArrayList<>();
    ArrayList<String> entrypointList = new ArrayList<>();
    if (commands != null && !commands.isEmpty()) {
        cmdList.add("-c");
        if (sut != null) {
            if (sut.isSutInNewContainer()) {
                commands = sutPath != null ? ("cd " + sutPath + ";" + commands) : commands;
            }
        } else {
            commands = "export ET_SUT_HOST=$(" + this.getThisContainerIpCmd + ") || echo;" + commands;
        }
        cmdList.add(commands);
        entrypointList.add("/bin/sh");
    }
    // Load Log Config
    LogConfig logConfig = null;
    if (tJob.isSelectedService("ems")) {
        try {
            logConfig = getEMSLogConfig(type, prefix, suffix, dockerExec);
        } catch (Exception e) {
            logger.error("", e);
        }
    } else {
        logConfig = getDefaultLogConfig(logPort, prefix, suffix, dockerExec);
    }
    // Pull Image
    this.pullETExecImage(image, type);
    // Create docker sock volume
    Volume dockerSockVolume = new Volume(dockerSock);
    CreateContainerCmd containerCmd = dockerExec.getDockerClient().createContainerCmd(image).withEnv(envList).withLogConfig(logConfig).withName(containerName).withCmd(cmdList).withEntrypoint(entrypointList).withNetworkMode(dockerExec.getNetwork());
    Volume sharedDataVolume = null;
    if (dockerExec.gettJobexec().getTjob().getSut() != null && dockerExec.gettJobexec().getTjob().getSut().isSutInNewContainer()) {
        sharedDataVolume = new Volume(sharedFolder);
    }
    if (sharedDataVolume != null) {
        containerCmd = containerCmd.withVolumes(dockerSockVolume, sharedDataVolume).withBinds(new Bind(dockerSock, dockerSockVolume), new Bind(sharedFolder, sharedDataVolume));
    } else {
        containerCmd = containerCmd.withVolumes(dockerSockVolume).withBinds(new Bind(dockerSock, dockerSockVolume));
    }
    // Create Container
    return containerCmd.exec();
}
Also used : Bind(com.github.dockerjava.api.model.Bind) TJobExecution(io.elastest.etm.model.TJobExecution) ArrayList(java.util.ArrayList) SutSpecification(io.elastest.etm.model.SutSpecification) TJob(io.elastest.etm.model.TJob) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotModifiedException(com.github.dockerjava.api.exception.NotModifiedException) DockerClientException(com.github.dockerjava.api.exception.DockerClientException) InternalServerErrorException(com.github.dockerjava.api.exception.InternalServerErrorException) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CreateContainerCmd(com.github.dockerjava.api.command.CreateContainerCmd) Volume(com.github.dockerjava.api.model.Volume) Parameter(io.elastest.etm.model.Parameter) Map(java.util.Map) HashMap(java.util.HashMap) LogConfig(com.github.dockerjava.api.model.LogConfig)

Example 4 with SutSpecification

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

the class SutApiItTest method testGetSuts.

@Test
public void testGetSuts() {
    log.info("Start the test testGetSuts");
    List<SutSpecification> tSutsToGet = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        tSutsToGet.add(createSut(projectId));
    }
    log.debug("GET /api/sut");
    ResponseEntity<SutSpecification[]> response = httpClient.getForEntity("/api/sut", SutSpecification[].class);
    SutSpecification[] suts = response.getBody();
    for (SutSpecification sut : suts) {
        deleteSut(sut.getId());
    }
    log.info("Suts Array size:" + suts.length);
    assertTrue(suts.length > 0);
}
Also used : ArrayList(java.util.ArrayList) SutSpecification(io.elastest.etm.model.SutSpecification) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with SutSpecification

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

the class ModelsTest method executionTest.

@Test
public void executionTest() {
    Project project = new Project(3l, "name", new ArrayList<TJob>(), new ArrayList<SutSpecification>());
    SutSpecification sut = new SutSpecification(34l, "name", "specification", "description", project, new ArrayList<>(), SutTypeEnum.REPOSITORY, false, null, InstrumentedByEnum.WITHOUT, null, ManagedDockerType.IMAGE, CommandsOptionEnum.DEFAULT);
    TJob tjob = new TJob(34l, "name", "imageName", sut, project, false, "execDashboardConfig", null);
    List<Parameter> params = new ArrayList<>();
    params.add(new Parameter(45l, "param1", "value1", tjob, null));
    tjob.setParameters(params);
    TJobExecution exec = new TJobExecution(45l, 34543534l, ResultEnum.SUCCESS);
    List<Parameter> paramsExec = new ArrayList<>();
    paramsExec.add(new Parameter(45l, "param1", "value1", tjob, exec));
    exec.setParameters(paramsExec);
    TJobExecution exec2 = new TJobExecution(45l, 34543534l, ResultEnum.SUCCESS);
    List<Parameter> paramsExec2 = new ArrayList<>();
    paramsExec2.add(new Parameter(45l, "param1", "value1", tjob, exec2));
    exec2.setParameters(paramsExec2);
    exec.setTjob(tjob);
    exec2.setTjob(tjob);
    SutExecution sutExec = new SutExecution(45l, sut, "ssss", DeployStatusEnum.DEPLOYED);
    SutExecution sutExec2 = new SutExecution(45l, sut, "ssss", DeployStatusEnum.DEPLOYED);
    exec.setSutExecution(sutExec);
    exec2.setSutExecution(sutExec2);
    assertEquals(exec, exec2);
    assertEquals(exec.hashCode(), exec2.hashCode());
}
Also used : Project(io.elastest.etm.model.Project) TJobExecution(io.elastest.etm.model.TJobExecution) SutExecution(io.elastest.etm.model.SutExecution) ArrayList(java.util.ArrayList) Parameter(io.elastest.etm.model.Parameter) SutSpecification(io.elastest.etm.model.SutSpecification) TJob(io.elastest.etm.model.TJob) Test(org.junit.jupiter.api.Test)

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