private void toString(StringBuilder b, String jobId, int depth) { IJobStatus status = getJobStatus(jobId); b.append(StringUtils.repeat(' ', depth * TO_STRING_INDENT)); b.append(StringUtils.leftPad(new PercentFormatter().format( status.getProgress()), TO_STRING_INDENT)); b.append(" ").append(status.getJobId()); b.append(System.lineSeparator()); for (IJobStatus child : getChildren(jobId)) { toString(b, child.getJobId(), depth + 1); } } }
@Override public void execute(JobStatusUpdater statusUpdater, JobSuite suite) { IJobStatus status = suite.getJobStatus(statusUpdater.getJobId()); if (!status.isResumed()) { startExecution(statusUpdater, suite); } else if (!status.isCompleted()) { resumeExecution(statusUpdater, suite); } }
config.setString("jobId", jobStatus.getJobId()); config.setDouble("progress", jobStatus.getProgress()); if (jobStatus.getNote() != null) { config.setString("note", jobStatus.getNote()); JobDuration duration = jobStatus.getDuration(); if (jobStatus.getResumeAttempts() > 0) { config.setInt("resumeAttempts", jobStatus.getResumeAttempts()); config.setDate("resumedStartTime", duration.getResumedStartTime()); config.setDate("resumedLastActivity", config.setDate("endTime", duration.getEndTime()); if (jobStatus.isStopping() || jobStatus.isStopped()) { config.setBoolean("stopped", true); Properties props = jobStatus.getProperties(); for (String key : props.keySet()) { config.put("prop." + key, props.get(key)); File file = getStatusFile(suiteName, jobStatus.getJobId()); if (LOG.isDebugEnabled()) { LOG.debug("Writing status file: " + file); FileLock lock = channel.lock()) { StringWriter sw = new StringWriter(); config.store(sw, "Status for job: " + jobStatus.getJobId()); ras.writeUTF(sw.toString());
private void backupSuite(JobSuiteStatusSnapshot statusTree) throws IOException { IJobStatus suiteStatus = statusTree.getRoot(); Date backupDate = suiteStatus.getDuration().getEndTime(); if (backupDate == null) { backupDate = suiteStatus.getLastActivity(); for (IJobStatus jobStatus : statuses) { getJobStatusStore().backup( getId(), jobStatus.getJobId(), backupDate);
private void stopJob(final IJob job, final IJobStatus status) { ((MutableJobStatus) status).setStopRequested(true); job.stop(status, suite); while (status.isRunning()) { Sleeper.sleepSeconds(STOP_WAIT_DELAY); } if (status.getState() == JobState.STOPPED) { for (IJobLifeCycleListener l : suite.getJobLifeCycleListeners()) { l.jobStopped(status); } if (job.getId().equals(suite.getRootJob().getId())) { for (ISuiteLifeCycleListener l : suite.getSuiteLifeCycleListeners()) { l.suiteStopped(suite); } } } }
private void flattenNode(JobStatusTreeNode node) { flattenNodes.put(node.jobStatus.getJobId(), node); for (JobStatusTreeNode childNode : node.children) { flattenNode(childNode); } }
} finally { stopMonitor.stopMonitoring(); JobState jobState = jobSuiteStatusSnapshot.getRoot().getState(); if (success) { if (jobState == JobState.COMPLETED) {
public List<IJobStatus> getChildren(IJobStatus jobStatus) { return getChildren(jobStatus.getJobId()); } public List<IJobStatus> getChildren(String jobId) {
public synchronized void childStatusChanged(IJobStatus status) { int jobIndex = jobIds.indexOf(status.getJobId()); if (jobIndex >= 0) { completionRatios[jobIndex] = status.getProgress(); } // Compute average double ratioTotal = 0; int completedCount = 0; for (int i = 0; i < completionRatios.length; i++) { if (completionRatios[i] >= 1.0d) { completedCount++; } ratioTotal += completionRatios[i]; } statusUpdater.setProgress(Math.min(1.0d, (ratioTotal / jobs.length))); statusUpdater.setNote(completedCount + " of " + jobs.length + " jobs completed."); }
public IJobStatus getParent(IJobStatus jobStatus) { return getParent(jobStatus.getJobId()); } public IJobStatus getParent(String jobId) {
jobId = event.getStatus().getJobId(); percent = Double.toString( event.getStatus().getProgress() * PROGRESS_RATIO);
@Override public String toString() { final StringBuilder b = new StringBuilder(); toString(b, getRoot().getJobId(), 0); return b.toString(); } private void toString(StringBuilder b, String jobId, int depth) {
private void writeJobId(Writer out, JobSuiteStatusSnapshot statusTree, IJobStatus status) throws IOException { out.write("<job name=\""); out.write(StringEscapeUtils.escapeXml10(status.getJobId())); out.write("\">"); for (IJobStatus child : statusTree.getChildren(status)) { writeJobId(out, statusTree, child); } out.write("</job>"); }
public void accept(IJobStatusVisitor visitor) { accept(visitor, getRoot().getJobId()); } private void accept(IJobStatusVisitor visitor, String jobId) {
private void accept(IJobStatusVisitor visitor, String jobId) { if (visitor != null) { visitor.visitJobStatus(getJobStatus(jobId)); for (IJobStatus child : getChildren(jobId)) { accept(visitor, child.getJobId()); } } }
@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);