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