Search in sources :

Example 1 with StageLogEntity

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();
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult) StageLogEntity(pipelite.entity.StageLogEntity) Stage(pipelite.stage.Stage) StageEntity(pipelite.entity.StageEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with StageLogEntity

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;
}
Also used : LogInfo(pipelite.controller.api.info.LogInfo) StageLogEntity(pipelite.entity.StageLogEntity) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 3 with StageLogEntity

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();
        }
    }
}
Also used : StageLogEntity(pipelite.entity.StageLogEntity) StageEntity(pipelite.entity.StageEntity)

Example 4 with StageLogEntity

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");
}
Also used : StageLogEntity(pipelite.entity.StageLogEntity) ProcessBuilder(pipelite.process.builder.ProcessBuilder) ProcessEntity(pipelite.entity.ProcessEntity) Stage(pipelite.stage.Stage) Process(pipelite.process.Process) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with StageLogEntity

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;
}
Also used : StageState(pipelite.stage.StageState) InternalErrorHandler(pipelite.error.InternalErrorHandler) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) ProcessEntity(pipelite.entity.ProcessEntity) Process(pipelite.process.Process) RetryTask(pipelite.executor.task.RetryTask) AdvancedConfiguration(pipelite.configuration.AdvancedConfiguration) ProcessState(pipelite.process.ProcessState) Stage(pipelite.stage.Stage) Flogger(lombok.extern.flogger.Flogger) Component(org.springframework.stereotype.Component) MailConfiguration(pipelite.configuration.MailConfiguration) Optional(java.util.Optional) ServiceConfiguration(pipelite.configuration.ServiceConfiguration) StageLogEntity(pipelite.entity.StageLogEntity) StageLogEntity(pipelite.entity.StageLogEntity) Stage(pipelite.stage.Stage)

Aggregations

StageLogEntity (pipelite.entity.StageLogEntity)7 Stage (pipelite.stage.Stage)5 Test (org.junit.jupiter.api.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 ProcessEntity (pipelite.entity.ProcessEntity)4 Process (pipelite.process.Process)4 ProcessBuilder (pipelite.process.builder.ProcessBuilder)3 StageEntity (pipelite.entity.StageEntity)2 Operation (io.swagger.v3.oas.annotations.Operation)1 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)1 Optional (java.util.Optional)1 Flogger (lombok.extern.flogger.Flogger)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)1 Component (org.springframework.stereotype.Component)1 AdvancedConfiguration (pipelite.configuration.AdvancedConfiguration)1 MailConfiguration (pipelite.configuration.MailConfiguration)1 ServiceConfiguration (pipelite.configuration.ServiceConfiguration)1 LogInfo (pipelite.controller.api.info.LogInfo)1