Search in sources :

Example 11 with JobState

use of org.apache.gobblin.runtime.JobState in project incubator-gobblin by apache.

the class SingleTask method run.

public void run() throws IOException, InterruptedException {
    List<WorkUnit> workUnits = getWorkUnits();
    JobState jobState = getJobState();
    Config jobConfig = getConfigFromJobState(jobState);
    _logger.debug("SingleTask.run: jobId {} workUnitFilePath {} jobStateFilePath {} jobState {} jobConfig {}", _jobId, _workUnitFilePath, _jobStateFilePath, jobState, jobConfig);
    try (SharedResourcesBroker<GobblinScopeTypes> globalBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(jobConfig, GobblinScopeTypes.GLOBAL.defaultScopeInstance())) {
        SharedResourcesBroker<GobblinScopeTypes> jobBroker = getJobBroker(jobState, globalBroker);
        _taskattempt = _taskAttemptBuilder.build(workUnits.iterator(), _jobId, jobState, jobBroker);
        _taskattempt.runAndOptionallyCommitTaskAttempt(GobblinMultiTaskAttempt.CommitPolicy.IMMEDIATE);
    }
}
Also used : GobblinScopeTypes(org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes) Config(com.typesafe.config.Config) JobState(org.apache.gobblin.runtime.JobState) MultiWorkUnit(org.apache.gobblin.source.workunit.MultiWorkUnit) WorkUnit(org.apache.gobblin.source.workunit.WorkUnit)

Example 12 with JobState

use of org.apache.gobblin.runtime.JobState in project incubator-gobblin by apache.

the class LocalJobLauncher method runWorkUnitStream.

@Override
protected void runWorkUnitStream(WorkUnitStream workUnitStream) throws Exception {
    String jobId = this.jobContext.getJobId();
    final JobState jobState = this.jobContext.getJobState();
    Iterator<WorkUnit> workUnitIterator = workUnitStream.getWorkUnits();
    if (!workUnitIterator.hasNext()) {
        LOG.warn("No work units to run");
        return;
    }
    TimingEvent workUnitsRunTimer = this.eventSubmitter.getTimingEvent(TimingEvent.RunJobTimings.WORK_UNITS_RUN);
    Iterator<WorkUnit> flattenedWorkUnits = new MultiWorkUnitUnpackingIterator(workUnitStream.getWorkUnits());
    Iterator<WorkUnit> workUnitsWithJobState = Iterators.transform(flattenedWorkUnits, new Function<WorkUnit, WorkUnit>() {

        @Override
        public WorkUnit apply(WorkUnit workUnit) {
            workUnit.addAllIfNotExist(jobState);
            return workUnit;
        }
    });
    GobblinMultiTaskAttempt.runWorkUnits(this.jobContext, workUnitsWithJobState, this.taskStateTracker, this.taskExecutor, GobblinMultiTaskAttempt.CommitPolicy.IMMEDIATE);
    if (this.cancellationRequested) {
        // Wait for the cancellation execution if it has been requested
        synchronized (this.cancellationExecution) {
            if (this.cancellationExecuted) {
                return;
            }
        }
    }
    workUnitsRunTimer.stop();
    LOG.info(String.format("All tasks of job %s have completed", jobId));
    if (jobState.getState() == JobState.RunningState.RUNNING) {
        jobState.setState(JobState.RunningState.SUCCESSFUL);
    }
}
Also used : MultiWorkUnitUnpackingIterator(org.apache.gobblin.runtime.util.MultiWorkUnitUnpackingIterator) JobState(org.apache.gobblin.runtime.JobState) WorkUnit(org.apache.gobblin.source.workunit.WorkUnit) TimingEvent(org.apache.gobblin.metrics.event.TimingEvent)

Example 13 with JobState

use of org.apache.gobblin.runtime.JobState in project incubator-gobblin by apache.

the class EmailNotificationJobListener method onJobCompletion.

@Override
public void onJobCompletion(JobContext jobContext) {
    JobState jobState = jobContext.getJobState();
    boolean alertEmailEnabled = Boolean.valueOf(jobState.getProp(ConfigurationKeys.ALERT_EMAIL_ENABLED_KEY, Boolean.toString(false)));
    boolean notificationEmailEnabled = Boolean.valueOf(jobState.getProp(ConfigurationKeys.NOTIFICATION_EMAIL_ENABLED_KEY, Boolean.toString(false)));
    // Send out alert email if the maximum number of consecutive failures is reached
    if (jobState.getState() == JobState.RunningState.FAILED) {
        int failures = jobState.getPropAsInt(ConfigurationKeys.JOB_FAILURES_KEY, 0);
        int maxFailures = jobState.getPropAsInt(ConfigurationKeys.JOB_MAX_FAILURES_KEY, ConfigurationKeys.DEFAULT_JOB_MAX_FAILURES);
        if (alertEmailEnabled && failures >= maxFailures) {
            try {
                EmailUtils.sendJobFailureAlertEmail(jobState.getJobName(), jobState.toString(), failures, jobState);
            } catch (EmailException ee) {
                LOGGER.error("Failed to send job failure alert email for job " + jobState.getJobId(), ee);
            }
            return;
        }
    }
    if (notificationEmailEnabled) {
        try {
            EmailUtils.sendJobCompletionEmail(jobState.getJobId(), jobState.toString(), jobState.getState().toString(), jobState);
        } catch (EmailException ee) {
            LOGGER.error("Failed to send job completion notification email for job " + jobState.getJobId(), ee);
        }
    }
}
Also used : EmailException(org.apache.commons.mail.EmailException) JobState(org.apache.gobblin.runtime.JobState)

Example 14 with JobState

use of org.apache.gobblin.runtime.JobState in project incubator-gobblin by apache.

the class EmailNotificationJobListener method onJobCancellation.

@Override
public void onJobCancellation(JobContext jobContext) {
    JobState jobState = jobContext.getJobState();
    boolean notificationEmailEnabled = Boolean.valueOf(jobState.getProp(ConfigurationKeys.NOTIFICATION_EMAIL_ENABLED_KEY, Boolean.toString(false)));
    if (notificationEmailEnabled) {
        try {
            EmailUtils.sendJobCancellationEmail(jobState.getJobId(), jobState.toString(), jobState);
        } catch (EmailException ee) {
            LOGGER.error("Failed to send job cancellation notification email for job " + jobState.getJobId(), ee);
        }
    }
}
Also used : EmailException(org.apache.commons.mail.EmailException) JobState(org.apache.gobblin.runtime.JobState)

Example 15 with JobState

use of org.apache.gobblin.runtime.JobState in project incubator-gobblin by apache.

the class RunOnceJobListener method onJobCompletion.

@Override
public void onJobCompletion(JobContext jobContext) {
    JobState jobState = jobContext.getJobState();
    if (!jobState.contains(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)) {
        LOG.error("Job configuration file path not found in job state of job " + jobState.getJobId());
        return;
    }
    String jobConfigFile = jobState.getProp(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY);
    // Rename the config file so we won't run this job when the worker is bounced
    try {
        Files.move(new File(jobConfigFile), new File(jobConfigFile + ".done"));
    } catch (IOException ioe) {
        LOG.error("Failed to rename job configuration file for job " + jobState.getJobName(), ioe);
    }
}
Also used : JobState(org.apache.gobblin.runtime.JobState) IOException(java.io.IOException) File(java.io.File)

Aggregations

JobState (org.apache.gobblin.runtime.JobState)15 Test (org.testng.annotations.Test)5 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)4 TaskState (org.apache.gobblin.runtime.TaskState)3 File (java.io.File)2 EmailException (org.apache.commons.mail.EmailException)2 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)2 TimingEvent (org.apache.gobblin.metrics.event.TimingEvent)2 JobContext (org.apache.gobblin.runtime.JobContext)2 Path (org.apache.hadoop.fs.Path)2 Config (com.typesafe.config.Config)1 IOException (java.io.IOException)1 GobblinScopeTypes (org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes)1 SourceState (org.apache.gobblin.configuration.SourceState)1 State (org.apache.gobblin.configuration.State)1 FsStateStore (org.apache.gobblin.metastore.FsStateStore)1 Tag (org.apache.gobblin.metrics.Tag)1 TaskContext (org.apache.gobblin.runtime.TaskContext)1 MultiWorkUnitUnpackingIterator (org.apache.gobblin.runtime.util.MultiWorkUnitUnpackingIterator)1 MultiWorkUnit (org.apache.gobblin.source.workunit.MultiWorkUnit)1