use of org.apache.helix.task.TaskDriver in project helix by apache.
the class JobAccessor method addJob.
@PUT
@Path("{jobName}")
public Response addJob(@PathParam("clusterId") String clusterId, @PathParam("workflowName") String workflowName, @PathParam("jobName") String jobName, String content) {
ZNRecord record;
TaskDriver driver = getTaskDriver(clusterId);
try {
record = toZNRecord(content);
JobConfig.Builder jobConfig = JobAccessor.getJobConfig(record);
driver.enqueueJob(workflowName, jobName, jobConfig);
} catch (HelixException e) {
return badRequest(String.format("Failed to enqueue job %s for reason : %s", jobName, e.getMessage()));
} catch (IOException e) {
return badRequest(String.format("Invalid input for Job Config of Job : %s", jobName));
}
return OK();
}
use of org.apache.helix.task.TaskDriver in project helix by apache.
the class JobAccessor method getJob.
@GET
@Path("{jobName}")
public Response getJob(@PathParam("clusterId") String clusterId, @PathParam("workflowName") String workflowName, @PathParam("jobName") String jobName) {
TaskDriver driver = getTaskDriver(clusterId);
Map<String, ZNRecord> jobMap = new HashMap<>();
JobConfig jobConfig = driver.getJobConfig(jobName);
if (jobConfig != null) {
jobMap.put(JobProperties.JobConfig.name(), jobConfig.getRecord());
} else {
return badRequest(String.format("Job config for %s does not exists", jobName));
}
JobContext jobContext = driver.getJobContext(jobName);
jobMap.put(JobProperties.JobContext.name(), null);
if (jobContext != null) {
jobMap.put(JobProperties.JobContext.name(), jobContext.getRecord());
}
return JSONRepresentation(jobMap);
}
use of org.apache.helix.task.TaskDriver in project helix by apache.
the class JobAccessor method getJobs.
@GET
public Response getJobs(@PathParam("clusterId") String clusterId, @PathParam("workflowName") String workflowName) {
TaskDriver driver = getTaskDriver(clusterId);
WorkflowConfig workflowConfig = driver.getWorkflowConfig(workflowName);
ObjectNode root = JsonNodeFactory.instance.objectNode();
if (workflowConfig == null) {
return badRequest(String.format("Workflow %s is not found!", workflowName));
}
Set<String> jobs = workflowConfig.getJobDag().getAllNodes();
root.put(Properties.id.name(), JobProperties.Jobs.name());
ArrayNode jobsNode = root.putArray(JobProperties.Jobs.name());
if (jobs != null) {
jobsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(jobs));
}
return JSONRepresentation(root);
}
use of org.apache.helix.task.TaskDriver in project helix by apache.
the class JobQueueResource method getHostedEntitiesRepresentation.
StringRepresentation getHostedEntitiesRepresentation(String clusterName, String jobQueueName) throws Exception {
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
TaskDriver taskDriver = new TaskDriver(zkClient, clusterName);
// Get job queue config
// TODO: fix this to use workflowConfig.
ResourceConfig jobQueueConfig = accessor.getProperty(keyBuilder.resourceConfig(jobQueueName));
// Get job queue context
WorkflowContext ctx = taskDriver.getWorkflowContext(jobQueueName);
// Create the result
ZNRecord hostedEntitiesRecord = new ZNRecord(jobQueueName);
if (jobQueueConfig != null) {
hostedEntitiesRecord.merge(jobQueueConfig.getRecord());
}
if (ctx != null) {
hostedEntitiesRecord.merge(ctx.getRecord());
}
StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(hostedEntitiesRecord), MediaType.APPLICATION_JSON);
return representation;
}
use of org.apache.helix.task.TaskDriver in project helix by apache.
the class WorkflowsResource method post.
@Override
public Representation post(Representation entity) {
try {
String clusterName = (String) getRequest().getAttributes().get("clusterName");
Form form = new Form(entity);
// Get the workflow and submit it
if (form.size() < 1) {
throw new HelixException("yaml workflow is required!");
}
Parameter payload = form.get(0);
String yamlPayload = payload.getName();
if (yamlPayload == null) {
throw new HelixException("yaml workflow is required!");
}
String zkAddr = (String) getContext().getAttributes().get(RestAdminApplication.ZKSERVERADDRESS);
HelixManager manager = HelixManagerFactory.getZKHelixManager(clusterName, null, InstanceType.ADMINISTRATOR, zkAddr);
manager.connect();
try {
Workflow workflow = Workflow.parse(yamlPayload);
TaskDriver driver = new TaskDriver(manager);
driver.start(workflow);
} finally {
manager.disconnect();
}
getResponse().setEntity(getHostedEntitiesRepresentation(clusterName));
getResponse().setStatus(Status.SUCCESS_OK);
} catch (Exception e) {
getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON);
getResponse().setStatus(Status.SUCCESS_OK);
LOG.error("Error in posting " + entity, e);
}
return null;
}
Aggregations