Search in sources :

Example 6 with TaskDriver

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);
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) TaskDriver(org.apache.helix.task.TaskDriver) WorkflowContext(org.apache.helix.task.WorkflowContext) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 7 with TaskDriver

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);
}
Also used : Entity(javax.ws.rs.client.Entity) WorkflowConfig(org.apache.helix.task.WorkflowConfig) JobQueue(org.apache.helix.task.JobQueue) TaskDriver(org.apache.helix.task.TaskDriver) Test(org.testng.annotations.Test)

Example 8 with TaskDriver

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");
}
Also used : TaskDriver(org.apache.helix.task.TaskDriver) JobConfig(org.apache.helix.task.JobConfig) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 9 with TaskDriver

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");
}
Also used : TaskDriver(org.apache.helix.task.TaskDriver) JobContext(org.apache.helix.task.JobContext) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 10 with TaskDriver

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();
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) HelixManager(org.apache.helix.HelixManager) TaskDriver(org.apache.helix.task.TaskDriver) File(java.io.File)

Aggregations

TaskDriver (org.apache.helix.task.TaskDriver)31 WorkflowConfig (org.apache.helix.task.WorkflowConfig)11 Path (javax.ws.rs.Path)9 GET (javax.ws.rs.GET)8 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 HelixException (org.apache.helix.HelixException)6 ZkClient (org.apache.helix.manager.zk.ZkClient)6 JobConfig (org.apache.helix.task.JobConfig)6 Workflow (org.apache.helix.task.Workflow)6 Test (org.testng.annotations.Test)6 ZNRecord (org.apache.helix.ZNRecord)5 JobQueue (org.apache.helix.task.JobQueue)4 WorkflowContext (org.apache.helix.task.WorkflowContext)4 ObjectNode (org.codehaus.jackson.node.ObjectNode)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Entity (javax.ws.rs.client.Entity)3 HelixManager (org.apache.helix.HelixManager)3 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)3