Search in sources :

Example 1 with JpaNifiEventStepExecution

use of com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiEventStepExecution 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

BatchStepExecution (com.thinkbiganalytics.metadata.api.jobrepo.step.BatchStepExecution)1 JpaBatchJobExecution (com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution)1 JpaNifiEventStepExecution (com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiEventStepExecution)1 DateTime (org.joda.time.DateTime)1