use of org.apache.helix.task.TaskDriver in project helix by apache.
the class WorkflowAccessor method getWorkflowContext.
@GET
@Path("{workflowId}/context")
public Response getWorkflowContext(@PathParam("clusterId") String clusterId, @PathParam("workflowId") String workflowId) {
TaskDriver taskDriver = getTaskDriver(clusterId);
WorkflowContext workflowContext = taskDriver.getWorkflowContext(workflowId);
ObjectNode workflowContextNode = JsonNodeFactory.instance.objectNode();
if (workflowContext != null) {
getWorkflowContextNode(workflowContextNode, workflowContext.getRecord());
}
return JSONRepresentation(workflowContextNode);
}
use of org.apache.helix.task.TaskDriver in project helix by apache.
the class TestWorkflowAccessor method testCreateWorkflow.
@Test(dependsOnMethods = "testGetWorkflowContext")
public void testCreateWorkflow() throws IOException {
System.out.println("Start test :" + TestHelper.getTestMethodName());
TaskDriver driver = getTaskDriver(CLUSTER_NAME);
// Create one time workflow
Entity entity = Entity.entity(WORKFLOW_INPUT, MediaType.APPLICATION_JSON_TYPE);
put("clusters/" + CLUSTER_NAME + "/workflows/" + TEST_WORKFLOW_NAME, null, entity, Response.Status.OK.getStatusCode());
WorkflowConfig workflowConfig = driver.getWorkflowConfig(TEST_WORKFLOW_NAME);
Assert.assertNotNull(workflowConfig);
Assert.assertEquals(workflowConfig.getJobDag().getAllNodes().size(), 2);
// Create JobQueue
JobQueue.Builder jobQueue = new JobQueue.Builder(TEST_QUEUE_NAME).setWorkflowConfig(driver.getWorkflowConfig(TEST_WORKFLOW_NAME));
entity = Entity.entity(OBJECT_MAPPER.writeValueAsString(Collections.singletonMap(WorkflowAccessor.WorkflowProperties.WorkflowConfig.name(), jobQueue.build().getWorkflowConfig().getRecord().getSimpleFields())), MediaType.APPLICATION_JSON_TYPE);
put("clusters/" + CLUSTER_NAME + "/workflows/" + TEST_QUEUE_NAME, null, entity, Response.Status.OK.getStatusCode());
workflowConfig = driver.getWorkflowConfig(TEST_QUEUE_NAME);
Assert.assertNotNull(workflowConfig);
Assert.assertTrue(workflowConfig.isJobQueue());
Assert.assertEquals(workflowConfig.getJobDag().getAllNodes().size(), 0);
}
use of org.apache.helix.task.TaskDriver in project helix by apache.
the class JobAccessor method getJobConfig.
@GET
@Path("{jobName}/configs")
public Response getJobConfig(@PathParam("clusterId") String clusterId, @PathParam("workflowName") String workflowName, @PathParam("jobName") String jobName) {
TaskDriver driver = getTaskDriver(clusterId);
JobConfig jobConfig = driver.getJobConfig(jobName);
if (jobConfig != null) {
return JSONRepresentation(jobConfig.getRecord());
}
return badRequest("Job config for " + jobName + " does not exists");
}
use of org.apache.helix.task.TaskDriver in project helix by apache.
the class JobAccessor method getJobContext.
@GET
@Path("{jobName}/context")
public Response getJobContext(@PathParam("clusterId") String clusterId, @PathParam("workflowName") String workflowName, @PathParam("jobName") String jobName) {
TaskDriver driver = getTaskDriver(clusterId);
JobContext jobContext = driver.getJobContext(jobName);
if (jobContext != null) {
return JSONRepresentation(jobContext.getRecord());
}
return badRequest("Job context for " + jobName + " does not exists");
}
use of org.apache.helix.task.TaskDriver in project helix by apache.
the class TaskAdmin method main.
/**
* Parses the first argument as a driver command and the rest of the
* arguments are parsed based on that command. Constructs a Helix
* message and posts it to the controller
*/
public static void main(String[] args) throws Exception {
String[] cmdArgs = Arrays.copyOfRange(args, 1, args.length);
CommandLine cl = parseOptions(cmdArgs, constructOptions(), args[0]);
String zkAddr = cl.getOptionValue(ZK_ADDRESS);
String clusterName = cl.getOptionValue(CLUSTER_NAME_OPTION);
String workflow = cl.getOptionValue(RESOURCE_OPTION);
if (zkAddr == null || clusterName == null || workflow == null) {
printUsage(constructOptions(), "[cmd]");
throw new IllegalArgumentException("zk, cluster, and resource must all be non-null for all commands");
}
HelixManager helixMgr = HelixManagerFactory.getZKHelixManager(clusterName, "Admin", InstanceType.ADMINISTRATOR, zkAddr);
helixMgr.connect();
TaskDriver driver = new TaskDriver(helixMgr);
try {
TaskDriver.DriverCommand cmd = TaskDriver.DriverCommand.valueOf(args[0]);
switch(cmd) {
case start:
if (cl.hasOption(WORKFLOW_FILE_OPTION)) {
driver.start(Workflow.parse(new File(cl.getOptionValue(WORKFLOW_FILE_OPTION))));
} else {
throw new IllegalArgumentException("Workflow file is required to start flow.");
}
break;
case stop:
driver.stop(workflow);
break;
case resume:
driver.resume(workflow);
break;
case delete:
driver.delete(workflow);
break;
case list:
list(driver, workflow);
break;
case flush:
driver.flushQueue(workflow);
break;
case clean:
driver.cleanupQueue(workflow);
break;
default:
throw new IllegalArgumentException("Unknown command " + args[0]);
}
} catch (IllegalArgumentException e) {
LOG.error("Unknown driver command " + args[0]);
throw e;
}
helixMgr.disconnect();
}
Aggregations