Search in sources :

Example 11 with PipeliteException

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;
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) PipeliteException(pipelite.exception.PipeliteException)

Example 12 with PipeliteException

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);
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) PipeliteException(pipelite.exception.PipeliteException) ScheduleEntity(pipelite.entity.ScheduleEntity)

Example 13 with PipeliteException

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);
}
Also used : ProcessQueue(pipelite.runner.process.ProcessQueue) ProcessRunnerFactory(pipelite.runner.process.ProcessRunnerFactory) PipeliteMetrics(pipelite.metrics.PipeliteMetrics) ProcessQueueFactory(pipelite.runner.process.ProcessQueueFactory) PipeliteException(pipelite.exception.PipeliteException) RegisteredPipelineService(pipelite.service.RegisteredPipelineService) ProcessEntityCreator(pipelite.runner.process.creator.ProcessEntityCreator) PipeliteConfiguration(pipelite.configuration.PipeliteConfiguration) Pipeline(pipelite.Pipeline) ProcessRunner(pipelite.runner.process.ProcessRunner) PipeliteServices(pipelite.service.PipeliteServices) ProcessQueueFactory(pipelite.runner.process.ProcessQueueFactory) ProcessRunnerFactory(pipelite.runner.process.ProcessRunnerFactory) RegisteredPipelineService(pipelite.service.RegisteredPipelineService) ProcessQueue(pipelite.runner.process.ProcessQueue) PipeliteException(pipelite.exception.PipeliteException) ProcessEntityCreator(pipelite.runner.process.creator.ProcessEntityCreator) ProcessRunner(pipelite.runner.process.ProcessRunner) Pipeline(pipelite.Pipeline)

Example 14 with PipeliteException

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);
}
Also used : StageEntityId(pipelite.entity.StageEntityId) PipeliteException(pipelite.exception.PipeliteException) StageEntity(pipelite.entity.StageEntity) Timed(io.micrometer.core.annotation.Timed)

Example 15 with PipeliteException

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;
}
Also used : StageExecutorResult(pipelite.stage.executor.StageExecutorResult) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PipeliteException(pipelite.exception.PipeliteException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

PipeliteException (pipelite.exception.PipeliteException)23 StageExecutorResult (pipelite.stage.executor.StageExecutorResult)6 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)5 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 Pod (io.fabric8.kubernetes.api.model.Pod)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Duration (java.time.Duration)2 ZonedDateTime (java.time.ZonedDateTime)2 TimeoutException (java.util.concurrent.TimeoutException)2 Pipeline (pipelite.Pipeline)2 Schedule (pipelite.Schedule)2 ProcessEntity (pipelite.entity.ProcessEntity)2 ScheduleEntity (pipelite.entity.ScheduleEntity)2 PipeliteMetrics (pipelite.metrics.PipeliteMetrics)2 ProcessBuilder (pipelite.process.builder.ProcessBuilder)2 PipeliteServices (pipelite.service.PipeliteServices)2 AWSBatch (com.amazonaws.services.batch.AWSBatch)1