use of pipelite.exception.PipeliteException in project pipelite by enasequence.
the class ProcessEntityCreator method create.
/**
* Creates and saves a process entity.
*
* @param processService the process service
* @param pipelineName the pipeline name
* @param process the process for which the process entity is created
* @return the created process entity or null if it could not be created
*/
public static ProcessEntity create(ProcessService processService, String pipelineName, Pipeline.Process process) {
String processId = process.getProcessId();
if (processId == null || processId.trim().isEmpty()) {
throw new PipeliteException("Failed to create process: missing process id");
}
ProcessEntity processEntity;
String trimmedProcessId = processId.trim();
Optional<ProcessEntity> savedProcessEntity = processService.getSavedProcess(pipelineName, trimmedProcessId);
if (savedProcessEntity.isPresent()) {
// Process entity already exists
processEntity = savedProcessEntity.get();
} else {
processEntity = processService.createExecution(pipelineName, trimmedProcessId, process.getPriority().getInt());
if (processEntity == null) {
throw new RuntimeException("Failed to create process: " + trimmedProcessId);
}
}
return processEntity;
}
use of pipelite.exception.PipeliteException in project pipelite by enasequence.
the class ScheduleRunner method createProcessEntity.
private ProcessEntity createProcessEntity(ScheduleCron scheduleCron) {
String pipelineName = scheduleCron.getPipelineName();
ScheduleEntity scheduleEntity = scheduleService.getSavedSchedule(pipelineName).get();
String lastProcessId = scheduleEntity.getProcessId();
String nextProcessId = nextProcessId(lastProcessId);
Optional<ProcessEntity> processEntity = processService.getSavedProcess(pipelineName, nextProcessId);
if (processEntity.isPresent()) {
throw new PipeliteException("Scheduled new process already exists: " + pipelineName + " " + nextProcessId);
}
return processService.createExecution(pipelineName, nextProcessId, ProcessEntity.DEFAULT_PRIORITY);
}
use of pipelite.exception.PipeliteException in project pipelite by enasequence.
the class PipelineRunnerFactory method create.
public static PipelineRunner create(PipeliteConfiguration pipeliteConfiguration, PipeliteServices pipeliteServices, PipeliteMetrics pipeliteMetrics, String pipelineName) {
// Get registered pipeline.
RegisteredPipelineService registeredPipelineService = pipeliteServices.registeredPipeline();
Pipeline pipeline = registeredPipelineService.getRegisteredPipeline(pipelineName, Pipeline.class);
if (pipeline == null) {
throw new PipeliteException("Missing pipeline: " + pipelineName);
}
// Get process creator.
ProcessEntityCreator processEntityCreator = new ProcessEntityCreator(pipeline, pipeliteServices.process());
ProcessQueueFactory processQueueFactory = (pipeline1) -> new ProcessQueue(pipeliteConfiguration, pipeliteServices, pipeline1);
boolean lockProcess = true;
ProcessRunnerFactory processRunnerFactory = (pipelineName1, process1) -> new ProcessRunner(pipeliteConfiguration, pipeliteServices, pipeliteMetrics, pipelineName1, process1, lockProcess);
return create(pipeliteConfiguration, pipeliteServices, pipeliteMetrics, pipeline, processEntityCreator, processQueueFactory, processRunnerFactory);
}
use of pipelite.exception.PipeliteException in project pipelite by enasequence.
the class StageService method createExecution.
/**
* Assigns a stage entity to the stage. Uses a saved stage entity if it exists or creates a new
* one. Saves the stage.
*
* @param pipelineName the pipeline name
* @param processId the process id
* @param stage the stage
*/
@Timed("pipelite.transactional")
public void createExecution(String pipelineName, String processId, Stage stage) {
// Uses saved stage if it exists.
Optional<StageEntity> savedStageEntity = repository.findById(new StageEntityId(processId, pipelineName, stage.getStageName()));
if (savedStageEntity.isPresent()) {
stage.setStageEntity(savedStageEntity.get());
}
StageEntity.createExecution(pipelineName, processId, stage);
if (stage.getStageEntity() == null) {
throw new PipeliteException("Failed to create new stage entity");
}
saveStage(stage);
}
use of pipelite.exception.PipeliteException in project pipelite by enasequence.
the class KubernetesExecutor method describeJobs.
public static Map<String, StageExecutorResult> describeJobs(List<String> requests, KubernetesDescribeJobsCache.ExecutorContext executorContext) {
log.atFine().log("Describing Kubernetes job results");
Map<String, StageExecutorResult> results = new HashMap<>();
Set<String> jobIds = new HashSet();
String namespace = executorContext.getNamespace();
try {
KubernetesClient client = executorContext.getKubernetesClient();
JobList jobList = RetryTask.DEFAULT.execute(r -> client.batch().v1().jobs().inNamespace(namespace).list());
for (Job job : jobList.getItems()) {
String jobId = job.getMetadata().getName();
jobIds.add(jobId);
results.put(jobId, describeJobsResult(namespace, jobId, client, job.getStatus()));
}
for (String jobId : requests) {
if (!jobIds.contains(jobId)) {
// Consider jobs that can't be found as failed.
results.put(jobId, StageExecutorResult.error());
}
}
} catch (KubernetesClientException e) {
throw new PipeliteException("Kubernetes error", e);
}
return results;
}
Aggregations