Search in sources :

Example 21 with TaskDriver

use of org.apache.helix.task.TaskDriver in project helix by apache.

the class WorkflowAccessor method getWorkflowConfig.

@GET
@Path("{workflowId}/configs")
public Response getWorkflowConfig(@PathParam("clusterId") String clusterId, @PathParam("workflowId") String workflowId) {
    TaskDriver taskDriver = getTaskDriver(clusterId);
    WorkflowConfig workflowConfig = taskDriver.getWorkflowConfig(workflowId);
    ObjectNode workflowConfigNode = JsonNodeFactory.instance.objectNode();
    if (workflowConfig != null) {
        getWorkflowConfigNode(workflowConfigNode, workflowConfig.getRecord());
    }
    return JSONRepresentation(workflowConfigNode);
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) ObjectNode(org.codehaus.jackson.node.ObjectNode) TaskDriver(org.apache.helix.task.TaskDriver) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 22 with TaskDriver

use of org.apache.helix.task.TaskDriver in project helix by apache.

the class TestJobAccessor method testCreateJob.

@Test(dependsOnMethods = "testGetJobContext")
public void testCreateJob() throws IOException {
    System.out.println("Start test :" + TestHelper.getTestMethodName());
    TaskDriver driver = getTaskDriver(CLUSTER_NAME);
    // Create JobQueue
    JobQueue.Builder jobQueue = new JobQueue.Builder(TEST_QUEUE_NAME).setWorkflowConfig(driver.getWorkflowConfig(WORKFLOW_NAME));
    Entity 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());
    // Test enqueue job
    entity = Entity.entity(JOB_INPUT, MediaType.APPLICATION_JSON_TYPE);
    put("clusters/" + CLUSTER_NAME + "/workflows/" + TEST_QUEUE_NAME + "/jobs/" + TEST_JOB_NAME, null, entity, Response.Status.OK.getStatusCode());
    String jobName = TaskUtil.getNamespacedJobName(TEST_QUEUE_NAME, TEST_JOB_NAME);
    JobConfig jobConfig = driver.getJobConfig(jobName);
    Assert.assertNotNull(jobConfig);
    WorkflowConfig workflowConfig = driver.getWorkflowConfig(TEST_QUEUE_NAME);
    Assert.assertTrue(workflowConfig.getJobDag().getAllNodes().contains(jobName));
}
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) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 23 with TaskDriver

use of org.apache.helix.task.TaskDriver in project helix by apache.

the class TestJobAccessor method testDeleteJob.

@Test(dependsOnMethods = "testCreateJob")
public void testDeleteJob() {
    System.out.println("Start test :" + TestHelper.getTestMethodName());
    TaskDriver driver = getTaskDriver(CLUSTER_NAME);
    delete("clusters/" + CLUSTER_NAME + "/workflows/" + TEST_QUEUE_NAME + "/jobs/" + TEST_JOB_NAME, Response.Status.OK.getStatusCode());
    String jobName = TaskUtil.getNamespacedJobName(TEST_QUEUE_NAME, TEST_JOB_NAME);
    JobConfig jobConfig = driver.getJobConfig(jobName);
    Assert.assertNull(jobConfig);
    WorkflowConfig workflowConfig = driver.getWorkflowConfig(TEST_QUEUE_NAME);
    Assert.assertTrue(!workflowConfig.getJobDag().getAllNodes().contains(jobName));
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) TaskDriver(org.apache.helix.task.TaskDriver) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 24 with TaskDriver

use of org.apache.helix.task.TaskDriver in project helix by apache.

the class TestWorkflowAccessor method testUpdateWorkflow.

@Test(dependsOnMethods = "testCreateWorkflow")
public void testUpdateWorkflow() {
    System.out.println("Start test :" + TestHelper.getTestMethodName());
    TaskDriver driver = getTaskDriver(CLUSTER_NAME);
    Entity entity = Entity.entity("", MediaType.APPLICATION_JSON_TYPE);
    post("clusters/" + CLUSTER_NAME + "/workflows/" + TEST_QUEUE_NAME, ImmutableMap.of("command", "stop"), entity, Response.Status.OK.getStatusCode());
    Assert.assertEquals(driver.getWorkflowConfig(TEST_QUEUE_NAME).getTargetState(), TargetState.STOP);
    post("clusters/" + CLUSTER_NAME + "/workflows/" + TEST_QUEUE_NAME, ImmutableMap.of("command", "resume"), entity, Response.Status.OK.getStatusCode());
    Assert.assertEquals(driver.getWorkflowConfig(TEST_QUEUE_NAME).getTargetState(), TargetState.START);
}
Also used : Entity(javax.ws.rs.client.Entity) TaskDriver(org.apache.helix.task.TaskDriver) Test(org.testng.annotations.Test)

Example 25 with TaskDriver

use of org.apache.helix.task.TaskDriver in project helix by apache.

the class TestWorkflowAccessor method testDeleteWorkflow.

@Test(dependsOnMethods = "testUpdateWorkflow")
public void testDeleteWorkflow() throws InterruptedException {
    System.out.println("Start test :" + TestHelper.getTestMethodName());
    TaskDriver driver = getTaskDriver(CLUSTER_NAME);
    int currentWorkflowNumbers = driver.getWorkflows().size();
    delete("clusters/" + CLUSTER_NAME + "/workflows/" + TEST_WORKFLOW_NAME, Response.Status.OK.getStatusCode());
    delete("clusters/" + CLUSTER_NAME + "/workflows/" + TEST_QUEUE_NAME, Response.Status.OK.getStatusCode());
    Thread.sleep(500);
    Assert.assertEquals(driver.getWorkflows().size(), currentWorkflowNumbers - 2);
}
Also used : TaskDriver(org.apache.helix.task.TaskDriver) Test(org.testng.annotations.Test)

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