if (!state.isFinalState()) { workingJobList.add(jobId);
public void updateJobOutput(String jobId, ExecutableState newStatus, Map<String, String> info, String output) { // when if (Thread.currentThread().isInterrupted()) { throw new RuntimeException("Current thread is interruptted, aborting"); } try { final ExecutableOutputPO jobOutput = executableDao.getJobOutput(jobId); Preconditions.checkArgument(jobOutput != null, "there is no related output for job id:" + jobId); ExecutableState oldStatus = ExecutableState.valueOf(jobOutput.getStatus()); if (newStatus != null && oldStatus != newStatus) { if (!ExecutableState.isValidStateTransfer(oldStatus, newStatus)) { throw new IllegalStateTranferException("there is no valid state transfer from:" + oldStatus + " to:" + newStatus + ", job id: " + jobId); } jobOutput.setStatus(newStatus.toString()); } if (info != null) { jobOutput.getInfo().putAll(info); } if (output != null) { jobOutput.setContent(output); } executableDao.updateJobOutput(jobOutput); logger.info("job id:" + jobId + " from " + oldStatus + " to " + newStatus); } catch (PersistentException e) { logger.error("error change job:" + jobId + " to " + newStatus); throw new RuntimeException(e); } }
@Override public int hashCode() { final int prime = 31; int hashCode = state.hashCode(); hashCode = hashCode * prime + extra.hashCode(); hashCode = hashCode * prime + verboseMsg.hashCode(); hashCode = hashCode * prime + Long.valueOf(lastModified).hashCode(); return hashCode; }
public void discardJob(String jobId) { AbstractExecutable job = getJob(jobId); if (job == null) { return; } if (job.getStatus().isFinalState()) { if (job.getStatus() != ExecutableState.DISCARDED) { logger.warn("The status of job " + jobId + " is " + job.getStatus().toString() + ". It's final state and cannot be transfer to be discarded!!!"); } else { logger.warn("The job " + jobId + " has been discarded."); } return; } if (job instanceof DefaultChainedExecutable) { List<AbstractExecutable> tasks = ((DefaultChainedExecutable) job).getTasks(); for (AbstractExecutable task : tasks) { if (!task.getStatus().isFinalState()) { updateJobOutput(task.getId(), ExecutableState.DISCARDED, null, null); } } } updateJobOutput(jobId, ExecutableState.DISCARDED, null, null); }
public void updateAllRunningJobsToError() { try { final List<ExecutableOutputPO> jobOutputs = executableDao.getJobOutputs(); for (ExecutableOutputPO executableOutputPO : jobOutputs) { if (executableOutputPO.getStatus().equalsIgnoreCase(ExecutableState.RUNNING.toString())) { executableOutputPO.setStatus(ExecutableState.ERROR.toString()); executableDao.updateJobOutput(executableOutputPO); } } } catch (PersistentException e) { logger.error("error reset job status from RUNNING to ERROR", e); throw new RuntimeException(e); } }
@Override public boolean apply(CheckpointExecutable executable) { try { ExecutableOutputPO executableOutputPO = allExecutableOutputPO .get(executable.getId()); ExecutableState state = ExecutableState.valueOf(executableOutputPO.getStatus()); return statusList.contains(state); } catch (Exception e) { throw e; } } }, new Predicate<CheckpointExecutable>() {
public ExecutableOutputPO getJobOutput(String uuid) throws PersistentException { ExecutableOutputPO result = null; try { result = readJobOutputResource(pathOfJobOutput(uuid)); if (result == null) { result = new ExecutableOutputPO(); result.setUuid(uuid); return result; } return result; } catch (IOException e) { logger.error("error get job output id:" + uuid, e); if (e.getCause() instanceof FileNotFoundException) { result = new ExecutableOutputPO(); result.setUuid(uuid); result.setStatus(ExecutableState.SUCCEED.name()); return result; } else { throw new PersistentException(e); } } }
public void resumeAllRunningJobs() { try { final List<ExecutableOutputPO> jobOutputs = executableDao.getJobOutputs(); for (ExecutableOutputPO executableOutputPO : jobOutputs) { if (executableOutputPO.getStatus().equalsIgnoreCase(ExecutableState.RUNNING.toString())) { executableOutputPO.setStatus(ExecutableState.READY.toString()); executableDao.updateJobOutput(executableOutputPO); } } } catch (PersistentException e) { logger.error("error reset job status from RUNNING to READY", e); throw new RuntimeException(e); } }
public void discardJob(String jobId) { AbstractExecutable job = getJob(jobId); if (job == null) { return; } if (job.getStatus().isFinalState()) { if (job.getStatus() != ExecutableState.DISCARDED) { logger.warn("The status of job " + jobId + " is " + job.getStatus().toString() + ". It's final state and cannot be transfer to be discarded!!!"); } else { logger.warn("The job " + jobId + " has been discarded."); } return; } if (job instanceof DefaultChainedExecutable) { List<AbstractExecutable> tasks = ((DefaultChainedExecutable) job).getTasks(); for (AbstractExecutable task : tasks) { if (!task.getStatus().isFinalState()) { updateJobOutput(task.getId(), ExecutableState.DISCARDED, null, null); } } } updateJobOutput(jobId, ExecutableState.DISCARDED, null, null); }
@Override public boolean apply(CubingJob executable) { try { ExecutableOutputPO executableOutputPO = allExecutableOutputPO .get(executable.getId()); ExecutableState state = ExecutableState.valueOf(executableOutputPO.getStatus()); return statusList.contains(state); } catch (Exception e) { throw e; } } }, new Predicate<CubingJob>() {
public ExecutableOutputPO getJobOutput(String uuid) throws PersistentException { ExecutableOutputPO result = null; try { result = readJobOutputResource(pathOfJobOutput(uuid)); if (result == null) { result = new ExecutableOutputPO(); result.setUuid(uuid); return result; } return result; } catch (IOException e) { logger.error("error get job output id:" + uuid, e); if (e.getCause() instanceof FileNotFoundException) { result = new ExecutableOutputPO(); result.setUuid(uuid); result.setStatus(ExecutableState.SUCCEED.name()); return result; } else { throw new PersistentException(e); } } }
public void updateJobOutput(String jobId, ExecutableState newStatus, Map<String, String> info, String output) { try { final ExecutableOutputPO jobOutput = executableDao.getJobOutput(jobId); Preconditions.checkArgument(jobOutput != null, "there is no related output for job id:" + jobId); ExecutableState oldStatus = ExecutableState.valueOf(jobOutput.getStatus()); if (newStatus != null && oldStatus != newStatus) { if (!ExecutableState.isValidStateTransfer(oldStatus, newStatus)) { throw new IllegalStateTranferException("there is no valid state transfer from:" + oldStatus + " to:" + newStatus); } jobOutput.setStatus(newStatus.toString()); } if (info != null) { jobOutput.setInfo(info); } if (output != null) { jobOutput.setContent(output); } executableDao.updateJobOutput(jobOutput); logger.info("job id:" + jobId + " from " + oldStatus + " to " + newStatus); } catch (PersistentException e) { logger.error("error change job:" + jobId + " to " + newStatus.toString()); throw new RuntimeException(e); } }
public void resetJobOutput(String jobId, ExecutableState state, String output) { try { final ExecutableOutputPO jobOutput = executableDao.getJobOutput(jobId); jobOutput.setStatus(state.toString()); if (output != null) { jobOutput.setContent(output); } executableDao.updateJobOutput(jobOutput); } catch (PersistentException e) { throw new RuntimeException(e); } }
if (!state.isFinalState()) { workingJobList.add(jobId); sb.append(jobId).append("(").append(state).append("), ");
private DefaultOutput parseOutput(ExecutableOutputPO jobOutput) { final DefaultOutput result = new DefaultOutput(); result.setExtra(jobOutput.getInfo()); result.setState(ExecutableState.valueOf(jobOutput.getStatus())); result.setVerboseMsg(jobOutput.getContent()); result.setLastModified(jobOutput.getLastModified()); return result; }
@Override public int hashCode() { final int prime = 31; int hashCode = state.hashCode(); hashCode = hashCode * prime + extra.hashCode(); hashCode = hashCode * prime + verboseMsg.hashCode(); hashCode = hashCode * prime + Long.valueOf(lastModified).hashCode(); return hashCode; }
public void updateJobOutput(String jobId, ExecutableState newStatus, Map<String, String> info, String output) { try { final ExecutableOutputPO jobOutput = executableDao.getJobOutput(jobId); Preconditions.checkArgument(jobOutput != null, "there is no related output for job id:" + jobId); ExecutableState oldStatus = ExecutableState.valueOf(jobOutput.getStatus()); if (newStatus != null && oldStatus != newStatus) { if (!ExecutableState.isValidStateTransfer(oldStatus, newStatus)) { throw new IllegalStateTranferException("there is no valid state transfer from:" + oldStatus + " to:" + newStatus); } jobOutput.setStatus(newStatus.toString()); } if (info != null) { jobOutput.setInfo(info); } if (output != null) { jobOutput.setContent(output); } executableDao.updateJobOutput(jobOutput); logger.info("job id:" + jobId + " from " + oldStatus + " to " + newStatus); } catch (PersistentException e) { logger.error("error change job:" + jobId + " to " + newStatus.toString()); throw new RuntimeException(e); } }
public void forceKillJob(String jobId) { try { final ExecutableOutputPO jobOutput = executableDao.getJobOutput(jobId); List<ExecutablePO> tasks = executableDao.getJob(jobId).getTasks(); for (ExecutablePO task : tasks) { if (executableDao.getJobOutput(task.getId()).getStatus().equals("SUCCEED")) { continue; } else if (executableDao.getJobOutput(task.getId()).getStatus().equals("RUNNING")) { updateJobOutput(task.getId(), ExecutableState.READY, Maps.<String, String> newHashMap(), ""); } break; } if (!jobOutput.getStatus().equals(ExecutableState.ERROR.toString())) { jobOutput.setStatus(ExecutableState.ERROR.toString()); executableDao.updateJobOutput(jobOutput); } } catch (PersistentException e) { throw new RuntimeException(e); } }
if (!state.isFinalState()) { String path = JobBuilderSupport.getJobWorkingDir(engineConfig.getHdfsWorkingDirectory(), jobId); allHdfsPathsNeedToBeDeleted.remove(path);
public Output getOutput(String uuid) { try { final ExecutableOutputPO jobOutput = executableDao.getJobOutput(uuid); Preconditions.checkArgument(jobOutput != null, "there is no related output for job id:" + uuid); final DefaultOutput result = new DefaultOutput(); result.setExtra(jobOutput.getInfo()); result.setState(ExecutableState.valueOf(jobOutput.getStatus())); result.setVerboseMsg(jobOutput.getContent()); result.setLastModified(jobOutput.getLastModified()); return result; } catch (PersistentException e) { logger.error("fail to get job output:" + uuid, e); throw new RuntimeException(e); } }