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; }
private void sendPost(String url, CallbackData data, CallbackContext context) { HttpPost post = new HttpPost(url); Set<Node> nodes; try { nodes = context.getClusterStoreView().getClusterNodes(data.getCluster().getId()); } catch (Exception e) { LOG.error("Unable to fetch nodes for cluster {}, not sending post request.", data.getCluster().getId()); return; } try { JsonObject body = new JsonObject(); body.add("cluster", gson.toJsonTree(data.getCluster())); body.add("job", gson.toJsonTree(data.getJob())); body.add("nodes", gson.toJsonTree(nodes)); post.setEntity(new StringEntity(gson.toJson(body))); httpClient.execute(post); } catch (UnsupportedEncodingException e) { LOG.warn("Exception setting http post body", e); } catch (ClientProtocolException e) { LOG.warn("Exception executing http post callback to " + url, e); } catch (IOException e) { LOG.warn("Exception executing http post callback to " + url, e); } catch (Exception e) { LOG.warn("Exception executing http post callback to " + url, e); } finally { post.releaseConnection(); } } }
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); } } }