/// <summary>Check and update the state of this job.</summary> /// <remarks> /// Check and update the state of this job. The state changes /// depending on its current state and the states of the depending jobs. /// </remarks> /// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> internal virtual ControlledJob.State CheckState() { lock (this) { if (this.state == ControlledJob.State.Running) { CheckRunningState(); } if (this.state != ControlledJob.State.Waiting) { return(this.state); } if (this.dependingJobs == null || this.dependingJobs.Count == 0) { this.state = ControlledJob.State.Ready; return(this.state); } Org.Apache.Hadoop.Mapreduce.Lib.Jobcontrol.ControlledJob pred = null; int n = this.dependingJobs.Count; for (int i = 0; i < n; i++) { pred = this.dependingJobs[i]; ControlledJob.State s = pred.CheckState(); if (s == ControlledJob.State.Waiting || s == ControlledJob.State.Ready || s == ControlledJob.State .Running) { break; } // a pred is still not completed, continue in WAITING // state if (s == ControlledJob.State.Failed || s == ControlledJob.State.DependentFailed) { this.state = ControlledJob.State.DependentFailed; this.message = "depending job " + i + " with jobID " + pred.GetJobID() + " failed. " + pred.GetMessage(); break; } // pred must be in success state if (i == n - 1) { this.state = ControlledJob.State.Ready; } } return(this.state); } }
/// <summary>Add a job to this jobs' dependency list.</summary> /// <remarks> /// Add a job to this jobs' dependency list. /// Dependent jobs can only be added while a Job /// is waiting to run, not during or afterwards. /// </remarks> /// <param name="dependingJob">Job that this Job depends on.</param> /// <returns><tt>true</tt> if the Job was added.</returns> public virtual bool AddDependingJob(Org.Apache.Hadoop.Mapreduce.Lib.Jobcontrol.ControlledJob dependingJob) { lock (this) { if (this.state == ControlledJob.State.Waiting) { //only allowed to add jobs when waiting if (this.dependingJobs == null) { this.dependingJobs = new AList <Org.Apache.Hadoop.Mapreduce.Lib.Jobcontrol.ControlledJob >(); } return(this.dependingJobs.AddItem(dependingJob)); } else { return(false); } } }