Search in sources :

Example 26 with Stage

use of pipelite.stage.Stage 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)

Example 27 with Stage

use of pipelite.stage.Stage in project pipelite by enasequence.

the class RetryService method retry.

/**
 * Retries a failed process.
 *
 * @param pipelineName the pipeline name
 * @param processId the processId
 * @throws PipeliteProcessRetryException if the process can't be retried
 */
public void retry(String pipelineName, String processId) {
    processService.isRetryProcess(pipelineName, processId);
    boolean isRetrySchedule = scheduleService.isRetrySchedule(pipelineName, processId);
    RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(pipelineName);
    Process process = ProcessFactory.create(processId, registeredPipeline);
    // Retry stages
    for (Stage stage : process.getStages()) {
        stage.setStageEntity(getSavedStage(pipelineName, processId, stage.getStageName()));
        if (DependencyResolver.isPermanentlyFailedStage(stage)) {
            stage.getStageEntity().resetExecution();
            stageService.saveStage(stage);
        }
    }
    // Retry process
    process.setProcessEntity(getSavedProcess(pipelineName, processId));
    processService.startExecution(process.getProcessEntity());
    // Retry schedule
    if (isRetrySchedule) {
        ScheduleRunner scheduler = runnerService.getScheduleRunner();
        if (scheduler == null) {
            throw new PipeliteProcessRetryException(pipelineName, processId, "missing scheduler");
        }
        scheduler.retrySchedule(pipelineName, processId);
    }
}
Also used : ScheduleRunner(pipelite.runner.schedule.ScheduleRunner) PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) Stage(pipelite.stage.Stage) RegisteredPipeline(pipelite.RegisteredPipeline) Process(pipelite.process.Process)

Example 28 with Stage

use of pipelite.stage.Stage in project pipelite by enasequence.

the class StageEntityTest method lifecycle.

@Test
public void lifecycle() {
    String pipelineName = PipeliteIdCreator.pipelineName();
    String processId = PipeliteIdCreator.processId();
    String stageName = PipeliteIdCreator.stageName();
    TestExecutor executor = new TestExecutor();
    executor.setExecutorParams(ExecutorParameters.builder().timeout(Duration.ofSeconds(0)).immediateRetries(0).maximumRetries(0).build());
    Stage stage = Stage.builder().stageName(stageName).executor(executor).build();
    // Create execution.
    StageEntity stageEntity = StageEntity.createExecution(pipelineName, processId, stage);
    StageService.prepareSaveStage(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.getErrorType()).isNull();
    assertThat(stageEntity.getResultParams()).isNull();
    assertThat(stageEntity.getStartTime()).isNull();
    assertThat(stageEntity.getEndTime()).isNull();
    assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.entity.StageEntityTest$TestExecutor");
    assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + "  \"test\" : \"TEST_EXECUTOR_DATA\"\n" + "}");
    assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 0,\n" + "  \"maximumRetries\" : 0,\n" + "  \"immediateRetries\" : 0,\n" + "  \"logLines\" : 1000\n" + "}");
    // Start first execution.
    stageEntity.startExecution();
    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.getErrorType()).isNull();
    assertThat(stageEntity.getResultParams()).isNull();
    assertThat(stageEntity.getStartTime()).isNotNull();
    assertThat(stageEntity.getEndTime()).isNull();
    assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.entity.StageEntityTest$TestExecutor");
    assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + "  \"test\" : \"TEST_EXECUTOR_DATA\"\n" + "}");
    assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 0,\n" + "  \"maximumRetries\" : 0,\n" + "  \"immediateRetries\" : 0,\n" + "  \"logLines\" : 1000\n" + "}");
    // End first execution.
    StageExecutorResult firstExecutionResult = StageExecutorResult.error();
    stageEntity.endExecution(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.getErrorType()).isEqualTo(ErrorType.EXECUTION_ERROR);
    assertThat(stageEntity.getResultParams()).isNull();
    assertThat(stageEntity.getStartTime()).isNotNull();
    assertThat(stageEntity.getEndTime()).isNotNull();
    assertThat(stageEntity.getStartTime()).isBeforeOrEqualTo(stageEntity.getEndTime());
    assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.entity.StageEntityTest$TestExecutor");
    assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + "  \"test\" : \"TEST_EXECUTOR_DATA\"\n" + "}");
    assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 0,\n" + "  \"maximumRetries\" : 0,\n" + "  \"immediateRetries\" : 0,\n" + "  \"logLines\" : 1000\n" + "}");
    // Start second execution.
    stageEntity.startExecution();
    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.getErrorType()).isNull();
    assertThat(stageEntity.getResultParams()).isNull();
    assertThat(stageEntity.getStartTime()).isNotNull();
    assertThat(stageEntity.getEndTime()).isNull();
    assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.entity.StageEntityTest$TestExecutor");
    assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + "  \"test\" : \"TEST_EXECUTOR_DATA\"\n" + "}");
    assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 0,\n" + "  \"maximumRetries\" : 0,\n" + "  \"immediateRetries\" : 0,\n" + "  \"logLines\" : 1000\n" + "}");
    // End second execution.
    StageExecutorResult secondExecutionResult = StageExecutorResult.success();
    stageEntity.endExecution(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.getErrorType()).isNull();
    assertThat(stageEntity.getResultParams()).isNull();
    assertThat(stageEntity.getStartTime()).isNotNull();
    assertThat(stageEntity.getEndTime()).isNotNull();
    assertThat(stageEntity.getStartTime()).isBeforeOrEqualTo(stageEntity.getEndTime());
    assertThat(stageEntity.getExecutorName()).isEqualTo("pipelite.entity.StageEntityTest$TestExecutor");
    assertThat(stageEntity.getExecutorData()).isEqualTo("{\n" + "  \"test\" : \"TEST_EXECUTOR_DATA\"\n" + "}");
    assertThat(stageEntity.getExecutorParams()).isEqualTo("{\n" + "  \"timeout\" : 0,\n" + "  \"maximumRetries\" : 0,\n" + "  \"immediateRetries\" : 0,\n" + "  \"logLines\" : 1000\n" + "}");
    // Reset execution.
    stageEntity.resetExecution();
    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.getErrorType()).isNull();
    assertThat(stageEntity.getResultParams()).isNull();
    assertThat(stageEntity.getStartTime()).isNull();
    assertThat(stageEntity.getEndTime()).isNull();
    assertThat(stageEntity.getExecutorName()).isNull();
    assertThat(stageEntity.getExecutorData()).isNull();
    assertThat(stageEntity.getExecutorParams()).isNull();
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult) Stage(pipelite.stage.Stage) Test(org.junit.jupiter.api.Test)

Example 29 with Stage

use of pipelite.stage.Stage in project pipelite by enasequence.

the class StageEntityTest method errorType.

@Test
public void errorType() {
    String pipelineName = PipeliteIdCreator.pipelineName();
    String processId = PipeliteIdCreator.processId();
    String stageName = PipeliteIdCreator.stageName();
    TestExecutor executor = new TestExecutor();
    Stage stage = Stage.builder().stageName(stageName).executor(executor).build();
    // Create execution.
    StageEntity stageEntity = StageEntity.createExecution(pipelineName, processId, stage);
    assertThat(stageEntity.getErrorType()).isNull();
    stageEntity.endExecution(StageExecutorResult.permanentError());
    assertThat(stageEntity.getErrorType()).isEqualTo(ErrorType.PERMANENT_ERROR);
    stageEntity = StageEntity.createExecution(pipelineName, processId, stage);
    assertThat(stageEntity.getErrorType()).isNull();
    stageEntity.endExecution(StageExecutorResult.internalError(new RuntimeException()));
    assertThat(stageEntity.getErrorType()).isEqualTo(ErrorType.INTERNAL_ERROR);
    stageEntity = StageEntity.createExecution(pipelineName, processId, stage);
    assertThat(stageEntity.getErrorType()).isNull();
    stageEntity.endExecution(StageExecutorResult.interruptedError());
    assertThat(stageEntity.getErrorType()).isEqualTo(ErrorType.INTERRUPTED_ERROR);
    stageEntity = StageEntity.createExecution(pipelineName, processId, stage);
    assertThat(stageEntity.getErrorType()).isNull();
    stageEntity.endExecution(StageExecutorResult.timeoutError());
    assertThat(stageEntity.getErrorType()).isEqualTo(ErrorType.TIMEOUT_ERROR);
    stageEntity = StageEntity.createExecution(pipelineName, processId, stage);
    assertThat(stageEntity.getErrorType()).isNull();
    stageEntity.endExecution(StageExecutorResult.error());
    assertThat(stageEntity.getErrorType()).isEqualTo(ErrorType.EXECUTION_ERROR);
}
Also used : Stage(pipelite.stage.Stage) Test(org.junit.jupiter.api.Test)

Example 30 with Stage

use of pipelite.stage.Stage in project pipelite by enasequence.

the class StageLogEntityTest method lifecycle.

@Test
public void lifecycle() {
    String pipelineName = PipeliteIdCreator.pipelineName();
    String processId = PipeliteIdCreator.processId();
    String stageName = PipeliteIdCreator.stageName();
    Stage stage = Stage.builder().stageName(stageName).executor(StageExecutor.createSyncTestExecutor(StageExecutorState.SUCCESS, null)).build();
    // Create execution.
    StageEntity.createExecution(pipelineName, processId, stage);
    // End execution.
    StageExecutorResult result = StageExecutorResult.error();
    result.setStageLog("TEST3");
    StageLogEntity stageLogEntity = StageLogEntity.endExecution(stage.getStageEntity(), result);
    assertThat(stageLogEntity.getPipelineName()).isEqualTo(pipelineName);
    assertThat(stageLogEntity.getProcessId()).isEqualTo(processId);
    assertThat(stageLogEntity.getStageName()).isEqualTo(stageName);
    assertThat(stageLogEntity.getStageLog()).isEqualTo("TEST3");
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult) Stage(pipelite.stage.Stage) Test(org.junit.jupiter.api.Test)

Aggregations

Stage (pipelite.stage.Stage)62 Test (org.junit.jupiter.api.Test)49 Process (pipelite.process.Process)28 ProcessBuilder (pipelite.process.builder.ProcessBuilder)21 StageEntity (pipelite.entity.StageEntity)15 StageState (pipelite.stage.StageState)15 StageExecutorRequest (pipelite.stage.executor.StageExecutorRequest)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 ProcessEntity (pipelite.entity.ProcessEntity)9 SimpleLsfExecutorParameters (pipelite.stage.parameters.SimpleLsfExecutorParameters)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 StageExecutorResult (pipelite.stage.executor.StageExecutorResult)6 StageLogEntity (pipelite.entity.StageLogEntity)5 ExecutorParameters (pipelite.stage.parameters.ExecutorParameters)3 ZonedDateTime (java.time.ZonedDateTime)2 Flogger (lombok.extern.flogger.Flogger)2 InternalErrorHandler (pipelite.error.InternalErrorHandler)2 SimpleLsfExecutor (pipelite.executor.SimpleLsfExecutor)2 SyncTestExecutor (pipelite.executor.SyncTestExecutor)2 ProcessState (pipelite.process.ProcessState)2