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