Search in sources :

Example 1 with JpaBatchJobExecution

use of com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution in project kylo by Teradata.

the class DefaultJobService method stopJobExecution.

@Override
public boolean stopJobExecution(ReplayJobExecution replayJobExecution) throws JobExecutionException {
    SavepointReplayJobExecution savepointReplayJobExecution = ((SavepointReplayJobExecution) replayJobExecution);
    return metadataAccess.commit(() -> {
        BatchJobExecution jobExecution = this.jobExecutionProvider.findByJobExecutionId(savepointReplayJobExecution.getJobExecutionId(), false);
        if (jobExecution != null) {
            ((JpaBatchJobExecution) jobExecution).markAsRunning();
            // ((JpaBatchJobExecution)jobExecution).failJob();
            // trigger the jms message
            SavepointReplayEvent event = new SavepointReplayEvent();
            event.setJobExecutionId(savepointReplayJobExecution.getJobExecutionId());
            event.setFlowfileId(savepointReplayJobExecution.getFlowFileId());
            event.setAction(SavepointReplayEvent.Action.RELEASE);
            savepointReplayJmsEventService.triggerSavepoint(event);
        }
        return true;
    });
}
Also used : JpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) SavepointReplayJobExecution(com.thinkbiganalytics.jobrepo.model.SavepointReplayJobExecution) SavepointReplayEvent(com.thinkbiganalytics.nifi.savepoint.model.SavepointReplayEvent) JpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution)

Example 2 with JpaBatchJobExecution

use of com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution in project kylo by Teradata.

the class DefaultJobService method restartJobExecution.

@Override
public Long restartJobExecution(ReplayJobExecution replayJobExecution) throws JobExecutionException {
    SavepointReplayJobExecution savepointReplayJobExecution = ((SavepointReplayJobExecution) replayJobExecution);
    return metadataAccess.commit(() -> {
        BatchJobExecution jobExecution = this.jobExecutionProvider.findByJobExecutionId(savepointReplayJobExecution.getJobExecutionId(), false);
        if (jobExecution != null) {
            ((JpaBatchJobExecution) jobExecution).markAsRunning();
            // trigger the jms message
            SavepointReplayEvent event = new SavepointReplayEvent();
            event.setJobExecutionId(savepointReplayJobExecution.getJobExecutionId());
            event.setFlowfileId(savepointReplayJobExecution.getFlowFileId());
            event.setAction(SavepointReplayEvent.Action.RETRY);
            savepointReplayJmsEventService.triggerSavepoint(event);
            return jobExecution.getJobExecutionId();
        }
        return null;
    });
}
Also used : JpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) SavepointReplayJobExecution(com.thinkbiganalytics.jobrepo.model.SavepointReplayJobExecution) SavepointReplayEvent(com.thinkbiganalytics.nifi.savepoint.model.SavepointReplayEvent) JpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution)

Example 3 with JpaBatchJobExecution

use of com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution in project kylo by Teradata.

the class JpaBatchStepExecutionProvider method createStepExecution.

// Drop on SetSavepoint indicates release on parent flowfile id
public BatchStepExecution createStepExecution(BatchJobExecution jobExecution, ProvenanceEventRecordDTO event) {
    // only create the step if it doesnt exist yet for this event
    JpaBatchStepExecution stepExecution = batchStepExecutionRepository.findByProcessorAndJobFlowFile(event.getComponentId(), event.getJobFlowFileId());
    if (stepExecution == null) {
        if (!"KYLO".equalsIgnoreCase(event.getEventType())) {
            stepExecution = new JpaBatchStepExecution();
            stepExecution.setJobExecution(jobExecution);
            stepExecution.setStartTime(event.getStartTime() != null ? DateTimeUtil.convertToUTC(event.getStartTime()) : DateTimeUtil.convertToUTC(event.getEventTime()).minus(event.getEventDuration()));
            stepExecution.setEndTime(DateTimeUtil.convertToUTC(event.getEventTime()));
            stepExecution.setStepName(event.getComponentName());
            if (StringUtils.isBlank(stepExecution.getStepName())) {
                stepExecution.setStepName("Unknown Step ");
            }
            log.info("New Step Execution {} on Job: {} using event {} ", stepExecution.getStepName(), jobExecution.getJobExecutionId(), event.getEventId());
            boolean failure = event.isFailure();
            if (failure) {
                // notify failure listeners
                failStep(jobExecution, stepExecution, event.getFlowFileUuid(), event.getComponentId());
                if (StringUtils.isBlank(stepExecution.getExitMessage())) {
                    stepExecution.setExitMessage(event.getDetails());
                }
            } else {
                stepExecution.completeStep();
            }
            // add in execution contexts
            assignStepExecutionContextMap(event, stepExecution);
            // Attach the NifiEvent object to this StepExecution
            JpaNifiEventStepExecution eventStepExecution = new JpaNifiEventStepExecution(jobExecution, stepExecution, event.getEventId(), event.getJobFlowFileId());
            eventStepExecution.setComponentId(event.getComponentId());
            eventStepExecution.setJobFlowFileId(event.getJobFlowFileId());
            stepExecution.setNifiEventStepExecution(eventStepExecution);
            Set<BatchStepExecution> steps = jobExecution.getStepExecutions();
            if (steps == null) {
                ((JpaBatchJobExecution) jobExecution).setStepExecutions(new HashSet<>());
            }
            // saving the StepExecution will cascade and save the nifiEventStep
            stepExecution = batchStepExecutionRepository.save(stepExecution);
            jobExecution.getStepExecutions().add(stepExecution);
        }
    } else {
        log.info("Updating step {} ", event.getComponentName());
        // update it
        assignStepExecutionContextMap(event, stepExecution);
        // update the timing info
        Long originatingNiFiEventId = stepExecution.getNifiEventStepExecution().getEventId();
        // only update the end time if the eventid is > than the first one
        if (event.getEventId() > originatingNiFiEventId) {
            DateTime newEndTime = DateTimeUtil.convertToUTC(event.getEventTime());
            if (newEndTime.isAfter(stepExecution.getEndTime())) {
                stepExecution.setEndTime(newEndTime);
            }
        } else {
            DateTime newStartTime = DateTimeUtil.convertToUTC(event.getStartTime());
            if (newStartTime.isBefore(stepExecution.getStartTime())) {
                stepExecution.setStartTime(newStartTime);
            }
        }
        boolean failure = event.isFailure();
        if (failure) {
            // notify failure listeners
            log.info("Failing Step");
            failStep(jobExecution, stepExecution, event.getFlowFileUuid(), event.getComponentId());
            if (StringUtils.isBlank(stepExecution.getExitMessage())) {
                stepExecution.setExitMessage(event.getDetails());
            }
        }
        stepExecution = batchStepExecutionRepository.save(stepExecution);
    }
    return stepExecution;
}
Also used : JpaNifiEventStepExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiEventStepExecution) BatchStepExecution(com.thinkbiganalytics.metadata.api.jobrepo.step.BatchStepExecution) JpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution) DateTime(org.joda.time.DateTime)

Aggregations

JpaBatchJobExecution (com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution)3 SavepointReplayJobExecution (com.thinkbiganalytics.jobrepo.model.SavepointReplayJobExecution)2 BatchJobExecution (com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution)2 SavepointReplayEvent (com.thinkbiganalytics.nifi.savepoint.model.SavepointReplayEvent)2 BatchStepExecution (com.thinkbiganalytics.metadata.api.jobrepo.step.BatchStepExecution)1 JpaNifiEventStepExecution (com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiEventStepExecution)1 DateTime (org.joda.time.DateTime)1