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);
}
}
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);
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
Aggregations