@Override public void visitJobStatus(IJobStatus jobStatus) { MutableJobStatus status = (MutableJobStatus) jobStatus; status.setStopRequested(false); JobDuration duration = status.getDuration(); if (status.isStarted() && !status.isCompleted()) { status.incrementResumeAttempts(); if (duration != null) { duration.setResumedStartTime( duration.getStartTime()); duration.setResumedLastActivity( status.getLastActivity()); } } } });
public String getJobId() { return status.getJobId(); }
public void incrementProgress(double increment) { status.setProgress(status.getProgress() + increment); statusUpdated(status); } public long getDuration() {
/** * Gets the job execution state. * @return execution state */ @Override public JobState getState() { // The order is important to establish status if (isAborted()) { return JobState.ABORTED; } if (isStopped()) { return JobState.STOPPED; } if (isStopping()) { return JobState.STOPPING; } if (isCompleted()) { return JobState.COMPLETED; } if (isPrematurlyEnded()) { return JobState.PREMATURE_TERMINATION; } if (isRunning()) { return JobState.RUNNING; } return JobState.UNKNOWN; }
MutableJobStatus jobStatus = new MutableJobStatus(jobId); File file = getStatusFile(suiteName, jobId); jobStatus.setLastActivity(new Date(file.lastModified())); return jobStatus; + new Date(file.lastModified())); jobStatus.setLastActivity(new Date(file.lastModified())); jobStatus.setProgress(config.getDouble("progress", 0d)); jobStatus.setNote(config.getString("note", null)); jobStatus.setResumeAttempts(config.getInt("resumeAttempts", 0)); duration.setStartTime(config.getDate("startTime", null)); duration.setEndTime(config.getDate("endTime", null)); jobStatus.setDuration(duration); jobStatus.setStopRequested(config.getBoolean("stopped", false)); Properties props = jobStatus.getProperties(); for (String key : config.keySet()) { if (key.startsWith("prop.")) {
if (status.getState() == JobState.COMPLETED) { LOG.info("Job skipped: " + job.getId() + " (already completed)"); fire(jobLifeCycleListeners, "jobSkipped", status); if (status.getResumeAttempts() == 0) { status.getDuration().setStartTime(new Date()); LOG.info("Running " + job.getId() + ": BEGIN (" + status.getDuration().getStartTime() + ")"); fire(jobLifeCycleListeners, "jobStarted", status); } else { + ": RESUME (" + new Date() + ")"); fire(jobLifeCycleListeners, "jobResumed", status); status.getDuration().setEndTime(null); status.setNote(""); new JobErrorEvent(e, this, status)); if (status != null) { status.setNote("Error occured: " + e.getLocalizedMessage()); status.getDuration().setEndTime(new Date()); try { getJobStatusStore().write(getId(), status); + ": END (" + status.getDuration().getStartTime() + ")"); if (status.getState() != JobState.STOPPING && status.getState() != JobState.STOPPED) { if (success) {
@Override public void run() { try { while(!terminate) { for (MutableJobStatus status : statuses) { status.setLastActivity( new Date(suite.getJobStatusStore().touch( suite.getId(), status.getJobId()))); } Sleeper.sleepMillis(HEARTBEAT_INTERVAL); } } catch (IOException e) { throw new JEFException("Cannot update status heartbeat.", e); } }
public Properties getProperties() { return status.getProperties(); } public double getProgress() {
/** * Checks whether the current progress status matches any of the supplied * statuses. * @param states one or more states to match * @return <code>true</code> if progress status matches supplied statuses * @since 2.0 */ @Override public boolean isState(JobState... states) { JobState thisState = getState(); for (JobState state : states) { if (thisState == state) { return true; } } return false; }
public double getProgress() { return status.getProgress(); } public void setProgress(double progress) {
public long getDuration() { return status.getDuration().getDuration(); } public void setNote(String note) {
private static JobStatusTreeNode createTreeNode( IJobStatus parentStatus, IJob job) { IJobStatus status = new MutableJobStatus(job.getId()); List<JobStatusTreeNode> childNodes = new ArrayList<>(); if (job instanceof IJobGroup) { IJob[] jobs = ((IJobGroup) job).getJobs(); for (IJob childJob : jobs) { JobStatusTreeNode childNode = createTreeNode(status, childJob); if (childNode != null) { childNodes.add(childNode); } } } return new JobStatusTreeNode(parentStatus, status, childNodes); }
public JobStatusUpdater(final MutableJobStatus status) { this.status = status; status.getProperties().addMapChangeListener( new IMapChangeListener<String, List<String>>() { @Override public void mapChanged(MapChangeEvent<String, List<String>> event) { statusUpdated(status); } }); }
private void initialize(boolean resumeIfIncomplete) throws IOException { JobSuiteStatusSnapshot statusTree = JobSuiteStatusSnapshot.newSnapshot(getSuiteIndexFile()); if (statusTree != null) { LOG.info("Previous execution detected."); MutableJobStatus status = (MutableJobStatus) statusTree.getRoot(); JobState state = status.getState(); ensureValidExecutionState(state); if (resumeIfIncomplete && !state.isOneOf( JobState.COMPLETED, JobState.PREMATURE_TERMINATION)) { LOG.info("Resuming from previous execution."); prepareStatusTreeForResume(statusTree); } else { // Back-up so we can start clean LOG.info("Backing up previous execution status and log files."); backupSuite(statusTree); statusTree = null; } } else { LOG.info("No previous execution detected."); } if (statusTree == null) { statusTree = JobSuiteStatusSnapshot.create( getRootJob(), getLogManager()); writeJobSuiteIndex(statusTree); } this.jobSuiteStatusSnapshot = statusTree; }
@Override protected void statusUpdated(MutableJobStatus status) { try { getJobStatusStore().write(getId(), status); } catch (IOException e) { throw new JEFException( "Cannot persist status update for job: " + status.getJobId(), e); } fire(jobLifeCycleListeners, "jobProgressed", status); IJobStatus parentStatus = jobSuiteStatusSnapshot.getParent(status); if (parentStatus != null) { IJobGroup jobGroup = (IJobGroup) jobs.get(parentStatus.getJobId()); if (jobGroup != null) { jobGroup.groupProgressed(status); } } } }, this);