Search in sources :

Example 11 with JobConfig

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

the class TestWorkflowJobDependency method testWorkflowWithOutDependencies.

@Test
public void testWorkflowWithOutDependencies() throws InterruptedException {
    String workflowName = TestHelper.getTestMethodName();
    // Workflow setup
    LOG.info("Start setup for workflow: " + workflowName);
    Workflow.Builder builder = new Workflow.Builder(workflowName);
    for (int i = 0; i < _numDbs; i++) {
        // Let each job delay for 2 secs.
        JobConfig.Builder jobConfig = new JobConfig.Builder().setCommand(MockTask.TASK_COMMAND).setTargetResource(_testDbs.get(i)).setTargetPartitionStates(Sets.newHashSet("SLAVE", "MASTER")).setJobCommandConfigMap(WorkflowGenerator.DEFAULT_COMMAND_CONFIG);
        String jobName = "job" + _testDbs.get(i);
        builder.addJob(jobName, jobConfig);
    }
    // Start workflow
    Workflow workflow = builder.build();
    _driver.start(workflow);
    // Wait until the workflow completes
    _driver.pollForWorkflowState(workflowName, TaskState.COMPLETED);
    WorkflowContext workflowContext = _driver.getWorkflowContext(workflowName);
    long startTime = workflowContext.getStartTime();
    long finishTime = workflowContext.getFinishTime();
    // Update the start time range.
    for (String jobName : workflow.getJobConfigs().keySet()) {
        JobContext context = _driver.getJobContext(jobName);
        LOG.info(String.format("JOB: %s starts from %s finishes at %s.", jobName, context.getStartTime(), context.getFinishTime()));
        // Find job start time range.
        startTime = Math.max(context.getStartTime(), startTime);
        finishTime = Math.min(context.getFinishTime(), finishTime);
    }
    // All jobs have a valid overlap time range.
    Assert.assertTrue(startTime <= finishTime);
}
Also used : WorkflowContext(org.apache.helix.task.WorkflowContext) Workflow(org.apache.helix.task.Workflow) JobContext(org.apache.helix.task.JobContext) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 12 with JobConfig

use of org.apache.helix.task.JobConfig 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 13 with JobConfig

use of org.apache.helix.task.JobConfig 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 14 with JobConfig

use of org.apache.helix.task.JobConfig 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();
}
Also used : HelixException(org.apache.helix.HelixException) TaskDriver(org.apache.helix.task.TaskDriver) IOException(java.io.IOException) ZNRecord(org.apache.helix.ZNRecord) JobConfig(org.apache.helix.task.JobConfig) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 15 with JobConfig

use of org.apache.helix.task.JobConfig 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);
}
Also used : HashMap(java.util.HashMap) TaskDriver(org.apache.helix.task.TaskDriver) JobContext(org.apache.helix.task.JobContext) ZNRecord(org.apache.helix.ZNRecord) JobConfig(org.apache.helix.task.JobConfig) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

JobConfig (org.apache.helix.task.JobConfig)16 Test (org.testng.annotations.Test)10 WorkflowConfig (org.apache.helix.task.WorkflowConfig)9 JobContext (org.apache.helix.task.JobContext)7 TaskDriver (org.apache.helix.task.TaskDriver)5 Workflow (org.apache.helix.task.Workflow)5 WorkflowContext (org.apache.helix.task.WorkflowContext)5 HashMap (java.util.HashMap)3 Path (javax.ws.rs.Path)3 JobQueue (org.apache.helix.task.JobQueue)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 GET (javax.ws.rs.GET)2 ZNRecord (org.apache.helix.ZNRecord)2 TaskConfig (org.apache.helix.task.TaskConfig)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 PUT (javax.ws.rs.PUT)1 Entity (javax.ws.rs.client.Entity)1 MultiWorkUnit (org.apache.gobblin.source.workunit.MultiWorkUnit)1