Search in sources :

Example 11 with TJobExecution

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

the class ExternalService method isReadyTJobForExternalExecution.

public ExternalJob isReadyTJobForExternalExecution(Long tJobExecId) {
    ExternalJob externalJob = runningExternalJobs.get(tJobExecId);
    if (externalJob.getTSServices() != null && externalJob.getTSServices().size() > 0) {
        TJobExecution tJobExecution = tJobService.getTJobExecById(externalJob.gettJobExecId());
        if (tJobExecution.getEnvVars() != null && !tJobExecution.getEnvVars().isEmpty()) {
            externalJob.setEnvVars(tJobExecution.getEnvVars());
            externalJob.setReady(true);
            return externalJob;
        } else {
            externalJob.setReady(false);
            return externalJob;
        }
    } else {
        externalJob.setReady(true);
        return externalJob;
    }
}
Also used : ExternalTJobExecution(io.elastest.etm.model.external.ExternalTJobExecution) TJobExecution(io.elastest.etm.model.TJobExecution) ExternalJob(io.elastest.etm.api.model.ExternalJob)

Example 12 with TJobExecution

use of io.elastest.etm.model.TJobExecution 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 13 with TJobExecution

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

the class TJobService method endExternalTJobExecution.

public void endExternalTJobExecution(long tJobExecId, int result) {
    logger.info("Finishing the external Job.");
    TJobExecution tJobExec = this.getTJobExecById(tJobExecId);
    tJobExec.setResult(ResultEnum.values()[result]);
    tJobExecRepositoryImpl.save(tJobExec);
    try {
        tJobExecOrchestratorService.deprovideServices(tJobExec);
    } catch (Exception e) {
        logger.error("Exception during desprovisioning of the TSS associated with an External TJob.");
    }
}
Also used : TJobExecution(io.elastest.etm.model.TJobExecution) HTTPException(javax.xml.ws.http.HTTPException) IOException(java.io.IOException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException)

Example 14 with TJobExecution

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

the class TJobExecutionApiItTest method testExecuteTJob.

private void testExecuteTJob(boolean withSut) throws InterruptedException, ExecutionException, TimeoutException, MultipleFailuresError {
    log.info("Start the test testExecuteTJob " + (withSut ? "with" : "without") + " SuT");
    TJob tJob;
    if (withSut) {
        Long sutId = createSut(projectId).getId();
        tJob = createTJob(projectId, sutId);
    } else {
        tJob = createTJob(projectId);
    }
    StompSession stompSession = connectToRabbitMQ(serverPort);
    log.info("POST /api/tjob/{tjobId}/exec");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    String body = "{\"tJobParams\" : [{\"Param1\":\"NewValue1\"}], \"sutParams\" : [{\"Param1\":\"NewValue1\"}]}";
    HttpEntity<String> entity = new HttpEntity<>(body, headers);
    Map<String, Object> urlParams = new HashMap<>();
    urlParams.put("tjobId", tJob.getId());
    ResponseEntity<TJobExecution> response = httpClient.postForEntity("/api/tjob/{tjobId}/exec", entity, TJobExecution.class, urlParams);
    TJobExecution exec = response.getBody();
    log.info("TJobExecution creation response: " + response);
    if (withSut) {
        String queueToSuscribe = "/topic/" + "sut.default_log." + exec.getId() + ".log";
        log.info("Sut log queue '" + queueToSuscribe + "'");
        WaitForMessagesHandler handler = new WaitForMessagesHandler();
        stompSession.subscribe(queueToSuscribe, handler);
        handler.waitForCompletion(5, TimeUnit.SECONDS);
        log.info("Sut log queue received a message");
    }
    String queueToSuscribe = "/topic/" + "test.default_log." + exec.getId() + ".log";
    log.info("TJob log queue '" + queueToSuscribe + "'");
    WaitForMessagesHandler handler = new WaitForMessagesHandler(msg -> msg.contains("BUILD SUCCESS") || msg.contains("BUILD FAILURE"));
    stompSession.subscribe(queueToSuscribe, handler);
    handler.waitForCompletion(180, TimeUnit.SECONDS);
    assertAll("Validating TJobExecution Properties", () -> assertNotNull(response.getBody()), () -> assertNotNull(response.getBody().getId()), () -> assertTrue(response.getBody().getTjob().getId().equals(urlParams.get("tjobId"))));
    while (true) {
        exec = getTJobExecutionById(exec.getId(), tJob.getId()).getBody();
        log.info("TJobExecution: " + exec);
        if (exec.getResult() != ResultEnum.IN_PROGRESS) {
            log.info("Test results:" + exec.getTestSuites());
            break;
        }
        sleep(500);
    }
    deleteTJobExecution(exec.getId(), tJob.getId());
    deleteTJob(tJob.getId());
    log.info("Finished.");
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) StompSession(org.springframework.messaging.simp.stomp.StompSession) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) TJobExecution(io.elastest.etm.model.TJobExecution) TJob(io.elastest.etm.model.TJob) WaitForMessagesHandler(io.elastest.etm.test.util.StompTestUtils.WaitForMessagesHandler)

Aggregations

TJobExecution (io.elastest.etm.model.TJobExecution)14 TJob (io.elastest.etm.model.TJob)6 IOException (java.io.IOException)6 SutSpecification (io.elastest.etm.model.SutSpecification)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HTTPException (javax.xml.ws.http.HTTPException)3 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)3 DockerClientException (com.github.dockerjava.api.exception.DockerClientException)2 InternalServerErrorException (com.github.dockerjava.api.exception.InternalServerErrorException)2 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)2 NotModifiedException (com.github.dockerjava.api.exception.NotModifiedException)2 Bind (com.github.dockerjava.api.model.Bind)2 Volume (com.github.dockerjava.api.model.Volume)2 Parameter (io.elastest.etm.model.Parameter)2 SutExecution (io.elastest.etm.model.SutExecution)2 ExternalTJobExecution (io.elastest.etm.model.external.ExternalTJobExecution)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXException (org.xml.sax.SAXException)2