@Override public String apply(ClusterTask clusterTask) { return clusterTask.getTaskId(); } };
/** * Return whether or not the task failed before it could create any resources, such as a node or a disk. * * @return true if the task failed before it could create any resources, false if not */ public boolean failedBeforeCreate() { int code = getStatusCode(); return clusterAction == ClusterAction.CLUSTER_CREATE && code > 199 && code < 300; }
public String getClusterId() { return jobId.getClusterId(); }
public ClusterTask(ProvisionerAction taskName, TaskId taskId, String nodeId, String service, ClusterAction clusterAction, String clusterTemplateName, Account account) { this.taskId = taskId.getId(); this.jobId = String.valueOf(taskId.getJobId().getId()); this.clusterId = taskId.getClusterId(); this.taskName = taskName; this.clusterAction = clusterAction; this.nodeId = nodeId; this.service = service; this.attempts = Lists.newArrayList(); //TODO: populate clusterTemplateName and account field for existing tasks: https://issues.cask.co/browse/COOPR-593 this.clusterTemplateName = clusterTemplateName; this.account = account; addAttempt(); }
@Override public PreparedStatement createUpdateStatement(Connection conn) throws SQLException { PreparedStatement updateStatement = conn.prepareStatement("UPDATE jobs SET job=?, status=? WHERE job_num=? AND cluster_id=?"); updateStatement.setBytes(1, jobBytes); updateStatement.setString(2, clusterJob.getJobStatus().name()); updateStatement.setLong(3, jobId.getJobNum()); updateStatement.setLong(4, clusterId); return updateStatement; }
/** * Sets the status of the given job to {@link ClusterJob.Status#FAILED} and the status of the cluster to the default * failure status as given in {@link co.cask.coopr.scheduler.ClusterAction#getFailureStatus()}. * * @param job Job to fail. * @param cluster Cluster to set the status for. * @throws IOException */ public void failJobAndSetClusterStatus(ClusterJob job, Cluster cluster) throws IOException, IllegalAccessException { failJobAndSetClusterStatus(job, cluster, job.getClusterAction().getFailureStatus(), null); }
/** * Sets the status message for the latest task attempt. * * @param statusMessage status message. */ public void setStatusMessage(String statusMessage) { attempts.get(currentAttemptIndex()).setStatusMessage(statusMessage); }
/** * Sets the status for the latest task attempt. * * @param status task status. */ public void setStatus(Status status) { attempts.get(currentAttemptIndex()).setStatus(status); }
/** * Sets the submit time for the latest task attempt. * * @param submitTime task submit time in ms. */ public void setSubmitTime(long submitTime) { attempts.get(currentAttemptIndex()).setSubmitTime(submitTime); }
/** * Get the latest task attempt status time. * * @return latest task attempt status time. */ public long getStatusTime() { return attempts.get(currentAttemptIndex()).getStatusTime(); }
/** * Sets the status code for the latest task attempt. * * @param statusCode status code. */ public void setStatusCode(int statusCode) { attempts.get(currentAttemptIndex()).setStatusCode(statusCode); }
/** * Get the latest task attempt status. * * @return latest task attempt status. */ public int getStatusCode() { return attempts.get(currentAttemptIndex()).getStatusCode(); }
/** * Get the latest task attempt status. * * @return latest task attempt status. */ public Status getStatus() { return attempts.get(currentAttemptIndex()).getStatus(); }
/** * Sets the status time for the latest task attempt. * * @param statusTime status time. */ public void setStatusTime(long statusTime) { attempts.get(currentAttemptIndex()).setStatusTime(statusTime); }
/** * Get the latest task attempt submit time. * * @return latest task attempt submit time. */ public long getSubmitTime() { return attempts.get(currentAttemptIndex()).getSubmitTime(); }
/** * Get the latest task attempt status message. * * @return latest task attempt status message. */ public String getStatusMessage() { return attempts.get(currentAttemptIndex()).getStatusMessage(); }
/** * Sets the status of the given job to {@link ClusterJob.Status#FAILED} and the status of the given cluster to * {@link co.cask.coopr.cluster.Cluster.Status#TERMINATED}. * * @param job Job to fail. * @param cluster Cluster to terminate. * @param message Error message. * @throws IOException */ public void failJobAndTerminateCluster(ClusterJob job, Cluster cluster, String message) throws IOException, IllegalAccessException { failJobAndSetClusterStatus(job, cluster, Cluster.Status.TERMINATED, message); }
public long getJobNum() { return jobId.getJobNum(); }
@Override public PreparedStatement createInsertStatement(Connection conn) throws SQLException { PreparedStatement statement = conn.prepareStatement( "INSERT INTO jobs (job_num, cluster_id, status, create_time, job) VALUES (?, ?, ?, ?, ?)"); statement.setLong(1, jobId.getJobNum()); statement.setLong(2, clusterId); statement.setString(3, clusterJob.getJobStatus().name()); statement.setTimestamp(4, DBHelper.getTimestamp(System.currentTimeMillis())); statement.setBytes(5, jobBytes); return statement; } }
@Override public String apply(ClusterTask clusterTask) { return clusterTask.getTaskId(); } };