use of pipelite.entity.StageLogEntity in project pipelite by enasequence.
the class StageServiceTest method lifecycle.
@Test
public void lifecycle() {
String pipelineName = PipeliteIdCreator.pipelineName();
String processId = PipeliteIdCreator.processId();
String stageName = PipeliteIdCreator.stageName();
TestExecutor executor = new TestExecutor(StageState.SUCCESS);
executor.setExecutorParams(ExecutorParameters.builder().immediateRetries(0).maximumRetries(1).timeout(Duration.ofSeconds(0)).build());
Stage stage = Stage.builder().stageName(stageName).executor(executor).build();
// Create execution.
service.createExecution(pipelineName, processId, stage);
StageEntity stageEntity = stage.getStageEntity();
assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
assertThat(stageEntity.getProcessId()).isEqualTo(processId);
assertThat(stageEntity.getStageName()).isEqualTo(stageName);
assertThat(stageEntity.getExecutionCount()).isEqualTo(0);
assertThat(stageEntity.getStageState()).isEqualTo(StageState.PENDING);
assertThat(stageEntity.getResultParams()).isNull();
assertThat(stageEntity.getStartTime()).isNull();
assertThat(stageEntity.getEndTime()).isNull();
assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.service.StageServiceTest$TestExecutor");
assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + " \"stageState\" : \"SUCCESS\"\n" + "}");
assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + " \"timeout\" : 0,\n" + " \"maximumRetries\" : 1,\n" + " \"immediateRetries\" : 0,\n" + " \"logLines\" : 1000\n" + "}");
// Start first execution.
service.startExecution(stage);
assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
assertThat(stageEntity.getProcessId()).isEqualTo(processId);
assertThat(stageEntity.getStageName()).isEqualTo(stageName);
assertThat(stageEntity.getExecutionCount()).isEqualTo(0);
assertThat(stageEntity.getStageState()).isEqualTo(StageState.ACTIVE);
assertThat(stageEntity.getResultParams()).isNull();
assertThat(stageEntity.getStartTime()).isNotNull();
assertThat(stageEntity.getEndTime()).isNull();
assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.service.StageServiceTest$TestExecutor");
assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + " \"stageState\" : \"SUCCESS\"\n" + "}");
assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + " \"timeout\" : 0,\n" + " \"maximumRetries\" : 1,\n" + " \"immediateRetries\" : 0,\n" + " \"logLines\" : 1000\n" + "}");
assertThat(service.getSavedStage(pipelineName, processId, stageName).get()).isEqualTo(stageEntity);
assertThat(service.getSavedStageLog(pipelineName, processId, stageName)).isNotPresent();
// End first execution.
StageExecutorResult firstExecutionResult = StageExecutorResult.error();
service.endExecution(stage, firstExecutionResult);
assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
assertThat(stageEntity.getProcessId()).isEqualTo(processId);
assertThat(stageEntity.getStageName()).isEqualTo(stageName);
assertThat(stageEntity.getExecutionCount()).isEqualTo(1);
assertThat(stageEntity.getStageState()).isEqualTo(StageState.ERROR);
assertThat(stageEntity.getResultParams()).isNull();
assertThat(stageEntity.getStartTime()).isNotNull();
assertThat(stageEntity.getEndTime()).isNotNull();
assertThat(stageEntity.getStartTime()).isBeforeOrEqualTo(stageEntity.getEndTime());
assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.service.StageServiceTest$TestExecutor");
assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + " \"stageState\" : \"SUCCESS\"\n" + "}");
assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + " \"timeout\" : 0,\n" + " \"maximumRetries\" : 1,\n" + " \"immediateRetries\" : 0,\n" + " \"logLines\" : 1000\n" + "}");
assertThat(service.getSavedStage(pipelineName, processId, stageName).get()).isEqualTo(stageEntity);
Optional<StageLogEntity> stageLogEntity = service.getSavedStageLog(pipelineName, processId, stageName);
assertThat(stageLogEntity).isPresent();
// Start second execution.
service.startExecution(stage);
assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
assertThat(stageEntity.getProcessId()).isEqualTo(processId);
assertThat(stageEntity.getStageName()).isEqualTo(stageName);
assertThat(stageEntity.getExecutionCount()).isEqualTo(1);
assertThat(stageEntity.getStageState()).isEqualTo(StageState.ACTIVE);
assertThat(stageEntity.getResultParams()).isNull();
assertThat(stageEntity.getStartTime()).isNotNull();
assertThat(stageEntity.getEndTime()).isNull();
assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.service.StageServiceTest$TestExecutor");
assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + " \"stageState\" : \"SUCCESS\"\n" + "}");
assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + " \"timeout\" : 0,\n" + " \"maximumRetries\" : 1,\n" + " \"immediateRetries\" : 0,\n" + " \"logLines\" : 1000\n" + "}");
assertThat(service.getSavedStage(pipelineName, processId, stageName).get()).isEqualTo(stageEntity);
assertThat(service.getSavedStageLog(pipelineName, processId, stageName)).isNotPresent();
// End second execution.
StageExecutorResult secondExecutionResult = StageExecutorResult.success();
service.endExecution(stage, secondExecutionResult);
assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
assertThat(stageEntity.getProcessId()).isEqualTo(processId);
assertThat(stageEntity.getStageName()).isEqualTo(stageName);
assertThat(stageEntity.getExecutionCount()).isEqualTo(2);
assertThat(stageEntity.getStageState()).isEqualTo(StageState.SUCCESS);
assertThat(stageEntity.getResultParams()).isNull();
assertThat(stageEntity.getStartTime()).isNotNull();
assertThat(stageEntity.getEndTime()).isNotNull();
assertThat(stageEntity.getStartTime()).isBeforeOrEqualTo(stageEntity.getEndTime());
assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.service.StageServiceTest$TestExecutor");
assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + " \"stageState\" : \"SUCCESS\"\n" + "}");
assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + " \"timeout\" : 0,\n" + " \"maximumRetries\" : 1,\n" + " \"immediateRetries\" : 0,\n" + " \"logLines\" : 1000\n" + "}");
assertThat(service.getSavedStage(pipelineName, processId, stageName).get()).isEqualTo(stageEntity);
stageLogEntity = service.getSavedStageLog(pipelineName, processId, stageName);
assertThat(stageLogEntity).isPresent();
// Reset execution.
service.resetExecution(stage);
assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
assertThat(stageEntity.getProcessId()).isEqualTo(processId);
assertThat(stageEntity.getStageName()).isEqualTo(stageName);
assertThat(stageEntity.getExecutionCount()).isEqualTo(0);
assertThat(stageEntity.getStageState()).isEqualTo(StageState.PENDING);
assertThat(stageEntity.getResultParams()).isNull();
assertThat(stageEntity.getStartTime()).isNull();
assertThat(stageEntity.getEndTime()).isNull();
assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.service.StageServiceTest$TestExecutor");
assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + " \"stageState\" : \"SUCCESS\"\n" + "}");
assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + " \"timeout\" : 0,\n" + " \"maximumRetries\" : 1,\n" + " \"immediateRetries\" : 0,\n" + " \"logLines\" : 1000\n" + "}");
assertThat(service.getSavedStage(pipelineName, processId, stageName).get()).isEqualTo(stageEntity);
assertThat(service.getSavedStageLog(pipelineName, processId, stageName)).isNotPresent();
}
use of pipelite.entity.StageLogEntity in project pipelite by enasequence.
the class LogController method logs.
@GetMapping("/{pipelineName}/{processId}/{stageName}")
@ResponseStatus(HttpStatus.OK)
@Operation(description = "Process logs")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "500", description = "Internal Server error") })
public LogInfo logs(@PathVariable(value = "pipelineName") String pipelineName, @PathVariable(value = "processId") String processId, @PathVariable(value = "stageName") String stageName) {
LogInfo logInfo = new LogInfo();
Optional<StageLogEntity> stageLogEntity = stageService.getSavedStageLog(pipelineName, processId, stageName);
if (stageLogEntity.isPresent()) {
logInfo.setLog(stageLogEntity.get().getStageLog());
}
return logInfo;
}
use of pipelite.entity.StageLogEntity in project pipelite by enasequence.
the class ScheduleRunnerTest method assertStageEntities.
private void assertStageEntities(TestSchedule f, String processId) {
String pipelineName = f.pipelineName();
TestProcessConfiguration t = f.getTestProcessConfiguration();
for (int i = 0; i < t.stageCnt; ++i) {
StageEntity stageEntity = stageService.getSavedStage(f.pipelineName(), processId, "STAGE" + i).get();
StageLogEntity stageLogEntity = stageService.getSavedStageLog(f.pipelineName(), processId, "STAGE" + i).get();
assertThat(stageEntity.getPipelineName()).isEqualTo(pipelineName);
assertThat(stageEntity.getProcessId()).isEqualTo(processId);
assertThat(stageEntity.getExecutionCount()).isEqualTo(1);
assertThat(stageEntity.getStartTime()).isNotNull();
assertThat(stageEntity.getEndTime()).isNotNull();
assertThat(stageEntity.getStartTime()).isBeforeOrEqualTo(stageEntity.getEndTime());
assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.executor.SyncTestExecutor");
assertThat(stageEntity.getExecutorData()).isNull();
assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + " \"timeout\" : 10000,\n" + " \"maximumRetries\" : 0,\n" + " \"immediateRetries\" : 0,\n" + " \"logLines\" : 1000\n" + "}");
if (t.stageTestResult == StageTestResult.ERROR) {
assertThat(stageEntity.getStageState()).isEqualTo(StageState.ERROR);
assertThat(stageEntity.getResultParams()).isNull();
} else if (t.stageTestResult == StageTestResult.EXCEPTION) {
assertThat(stageEntity.getStageState()).isEqualTo(StageState.ERROR);
assertThat(stageLogEntity.getStageLog()).contains("java.lang.RuntimeException: Expected exception");
} else {
assertThat(stageEntity.getStageState()).isEqualTo(StageState.SUCCESS);
assertThat(stageEntity.getResultParams()).isNull();
}
}
}
use of pipelite.entity.StageLogEntity in project pipelite by enasequence.
the class MailServiceTest method sendFailedStageExecutionMessageWithEmptyLog.
@Test
public void sendFailedStageExecutionMessageWithEmptyLog() {
String pipelineName = PipeliteIdCreator.pipelineName();
String processId = PipeliteIdCreator.processId();
Process process = new ProcessBuilder(processId).execute("STAGE1").withSyncTestExecutor().build();
Stage stage = process.getStage("STAGE1").get();
StageEntity.createExecution(pipelineName, processId, stage).setStageState(StageState.ERROR);
StageLogEntity stageLogEntity = new StageLogEntity();
stageLogEntity.setPipelineName(pipelineName);
stageLogEntity.setProcessId(processId);
stageLogEntity.setStageName("STAGE1");
stageLogEntity.setStageLog("");
stageService.saveStageLog(stageLogEntity);
ProcessEntity processEntity = new ProcessEntity();
processEntity.setPipelineName(pipelineName);
processEntity.setProcessId(processId);
processEntity.setProcessState(ProcessState.PENDING);
processEntity.setPriority(5);
process.setProcessEntity(processEntity);
process.setProcessEntity(processEntity);
assertThat(mailService.getStageExecutionSubject(process, stage)).isEqualTo("Pipelite stage (ERROR): " + pipelineName + "/" + processId + "/STAGE1");
assertThat(mailService.getExecutionBody(process, "SUBJECT")).isEqualTo("SUBJECT\n" + "\n" + "Process:\n" + "---------------\n" + "{\n" + " \"processId\" : \"" + processId + "\",\n" + " \"pipelineName\" : \"" + pipelineName + "\",\n" + " \"processState\" : \"PENDING\",\n" + " \"executionCount\" : 0,\n" + " \"priority\" : 5\n" + "}\n" + "\n" + "Stages:\n" + "---------------\n" + "{\n" + " \"processId\" : \"" + processId + "\",\n" + " \"pipelineName\" : \"" + pipelineName + "\",\n" + " \"stageName\" : \"STAGE1\",\n" + " \"stageState\" : \"ERROR\",\n" + " \"executionCount\" : 0\n" + "}\n" + "\n" + "Error logs:\n" + "---------------\n");
}
use of pipelite.entity.StageLogEntity in project pipelite by enasequence.
the class MailService method getStagesLogText.
String getStagesLogText(Process process) {
if (!process.getStages().stream().anyMatch(s -> s.isError())) {
return "";
}
String text = "\nError logs:\n---------------\n";
for (Stage stage : process.getStages()) {
if (stage.isError()) {
Optional<StageLogEntity> stageLogEntity = stageService.getSavedStageLog(process.getProcessEntity().getPipelineName(), process.getProcessId(), stage.getStageName());
if (stageLogEntity.isPresent()) {
String log = stageLogEntity.get().getStageLog();
if (log != null && !log.isEmpty()) {
text += "\nStage: " + stage.getStageName() + "\n===============\n";
text += log.substring(Math.max(0, log.length() - advancedConfiguration.getMailLogBytes())) + "\n";
}
}
}
}
return text;
}
Aggregations