public ClusterJobProgress(ClusterJob job) { this.action = job.getClusterAction(); this.actionstatus = job.getJobStatus(); this.stepstotal = job.getTaskStatus().size(); int completedTasks = 0; for (ClusterTask.Status taskStatus : job.getTaskStatus().values()) { if (taskStatus == ClusterTask.Status.COMPLETE) { completedTasks++; } } this.stepscompleted = completedTasks; }
/** * 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); }
public void onSuccess(CallbackData data, CallbackContext context) { ClusterAction jobAction = data.getJob().getClusterAction(); if (successTriggerActions.contains(data.getJob().getClusterAction())) { if (onSuccessUrl != null) { LOG.debug("{} completed successfully on cluster {}, sending request to {}", jobAction, data.getCluster().getId(), onSuccessUrl); sendPost(onSuccessUrl, data, context); } } }
@Override public void onFailure(CallbackData data, CallbackContext context) { ClusterAction jobAction = data.getJob().getClusterAction(); if (failureTriggerActions.contains(data.getJob().getClusterAction())) { if (onFailureUrl != null) { LOG.debug("{} failed on cluster {}, sending request to {}", jobAction, data.getCluster().getId(), onFailureUrl); sendPost(onFailureUrl, data, context); } } }
public boolean onStart(CallbackData data, CallbackContext context) { ClusterAction jobAction = data.getJob().getClusterAction(); if (startTriggerActions.contains(jobAction)) { if (onStartUrl != null) { LOG.debug("sending request to {} before performing {} on cluster {}", onStartUrl, jobAction, data.getCluster().getId()); sendPost(onStartUrl, data, context); } } return true; }
public ClusterStatusResponse(Cluster cluster, ClusterJob job) { this.clusterid = cluster.getId(); this.status = cluster.getStatus(); this.actionstatus = job.getJobStatus(); this.action = job.getClusterAction(); Map<String, ClusterTask.Status> taskStatus = job.getTaskStatus(); int completedTasks = 0; for (Map.Entry<String, ClusterTask.Status> entry : taskStatus.entrySet()) { if (entry.getValue().equals(ClusterTask.Status.COMPLETE)) { completedTasks++; } } this.stepscompleted = completedTasks; this.stepstotal = taskStatus.size(); }
private JsonObject formatJobPlan(ClusterJob job) throws IOException { JsonObject jobJson = new JsonObject(); jobJson.addProperty("id", job.getJobId()); jobJson.addProperty("clusterId", job.getClusterId()); jobJson.addProperty("action", job.getClusterAction().name()); jobJson.addProperty("currentStage", job.getCurrentStageNumber()); JsonArray stagesJson = new JsonArray(); for (Set<String> stage : job.getStagedTasks()) { JsonArray stageJson = new JsonArray(); for (String taskId : stage) { ClusterTask task = clusterStore.getClusterTask(TaskId.fromString(taskId)); JsonObject taskJson = new JsonObject(); taskJson.addProperty("id", task.getTaskId()); taskJson.addProperty("taskName", task.getTaskName().name()); taskJson.addProperty("nodeId", task.getNodeId()); taskJson.addProperty("service", task.getService()); stageJson.add(taskJson); } stagesJson.add(stageJson); } jobJson.add("stages", stagesJson); return jobJson; }
public JobPlanner(ClusterJob job, Set<Node> clusterNodes) { this.clusterAction = job.getClusterAction(); this.nodesToPlan = job.getPlannedNodes(); this.serviceNodeMap = ArrayListMultimap.create(); this.serviceMap = Maps.newHashMap(); this.nodeMap = Maps.newHashMap(); for (Node node : clusterNodes) { for (Service service : node.getServices()) { serviceNodeMap.put(service.getName(), node); serviceMap.put(service.getName(), service); } nodeMap.put(node.getId(), node); } this.dependencyResolver = new ServiceDependencyResolver(actions, serviceMap); if (job.getPlannedServices() != null) { this.servicesToPlan = ImmutableSet.copyOf(expandServices(job.getPlannedServices(), clusterAction)); } else { this.servicesToPlan = null; } }
/** * Sets the status of the given job to {@link ClusterJob.Status#COMPLETE} and the status of the given cluster to * {@link co.cask.coopr.cluster.Cluster.Status#ACTIVE}. * * @param job Job to complete. * @param cluster Cluster the job was for. * @throws IOException */ public void completeJob(ClusterJob job, Cluster cluster) throws IOException, IllegalAccessException { job.setJobStatus(ClusterJob.Status.COMPLETE); clusterStore.writeClusterJob(job); LOG.debug("Job {} is complete", job.getJobId()); // Update cluster status if (job.getClusterAction() == ClusterAction.CLUSTER_DELETE) { cluster.setStatus(Cluster.Status.TERMINATED); } else { cluster.setStatus(Cluster.Status.ACTIVE); } clusterStore.writeCluster(cluster); serverStats.getSuccessfulClusterStats().incrementStat(job.getClusterAction()); if (job.getClusterAction() == ClusterAction.CLUSTER_DELETE) { wipeSensitiveFields(cluster); } callbackQueues.add(cluster.getAccount().getTenantId(), new Element(gson.toJson(new CallbackData(CallbackData.Type.SUCCESS, cluster, job)))); }
private void onStart(CallbackData callbackData, CallbackContext callbackContext) { ClusterJob job = callbackData.getJob(); Cluster cluster = callbackData.getCluster(); try { if (clusterCallback.onStart(callbackData, callbackContext)) { String jobId = callbackData.getJob().getJobId(); jobQueues.add(gElement.getQueueName(), new Element(jobId)); LOG.debug("added job {} to job queue", jobId); } else { switch (job.getClusterAction()) { case CLUSTER_CREATE: taskService.failJobAndTerminateCluster(job, cluster, "Cluster creation stopped by failed start callback."); break; default: // failed to plan means the job should fail, but state has already been changed so the cluster // state in the db is inconsistent with reality. // TODO: Should revert it here but need versioning or cluster history or something to that effect. taskService.failJobAndSetClusterStatus( job, cluster, Cluster.Status.INCONSISTENT, "Failed to schedule the " + job.getClusterAction() + " operation."); break; } } } catch (Exception e) { LOG.error("Exception failing job {} for cluster {}", job.getJobId(), cluster.getId(), e); } } }
if (job.getClusterAction() == ClusterAction.CLUSTER_CREATE && allCreateTasksFailed(job)) { String message = job.getStatusMessage();
/** * Sets the status of the given job to {@link ClusterJob.Status#FAILED} and the status of the cluster to some given * status. * * @param job Job to fail. * @param cluster Cluster to set the status for. * @param status Status to set the cluster to. * @param message Error message. * @throws IOException * @throws IllegalAccessException */ public void failJobAndSetClusterStatus(ClusterJob job, Cluster cluster, Cluster.Status status, String message) throws IOException, IllegalAccessException { cluster.setStatus(status); clusterStore.writeCluster(cluster); job.setJobStatus(ClusterJob.Status.FAILED); if (message != null) { job.setStatusMessage(message); } clusterStore.writeClusterJob(job); serverStats.getFailedClusterStats().incrementStat(job.getClusterAction()); callbackQueues.add(cluster.getAccount().getTenantId(), new Element(gson.toJson(new CallbackData(CallbackData.Type.FAILURE, cluster, job)))); }
Assert.assertEquals(ClusterAction.CLUSTER_DELETE, delJob1.getClusterAction()); Assert.assertEquals(ClusterAction.CLUSTER_DELETE, delJob2.getClusterAction());
if (!(clusterJob.getClusterAction() == ClusterAction.CLUSTER_CREATE && clusterJob.getJobStatus() == ClusterJob.Status.RUNNING)) { throw new IllegalStateException("Cannot be aborted at this time.");